Code Red > .NET

AddVertexAt

(1/4) > >>

Bryco:
If you don't know the amount of verticies required when you create the pline and you want to keep adding verticies or if you want to add a verticie to an existing pline, I seem to get an elock problem.
oPline.UpgradeOpen(); doesn't seem to help.
When adding a new entity, the blocktable and the BlockTableRecord need OpenMode.ForWrite, is this necessary for modifying an entity?

MickD:
yes, with OpenForRead you can 'study' the object and get it's properties but if you want to change it you need to tell the db that you're taking control of the object which means no one else can use it while you have it to avoid multiple user issues.

MickD:
To elaborate a bit further, a symbol table record is just like a normal db record, you need to create it first (which means it's automatically open for writing at that point), add your data to the necessary fields and close it. If you want to edit it you need to get the record, open it for editing and so on.
hth.

Bryco:
Thanks Mick, I'll try that on the weekend

sinc:
If all you want to do is edit an existing polyline, you do not need to do anything with Block Tables or Block Table Records.

However, you DO need to open the polyline itself for write.  You can do this by opening it for write, or by opening it for read and using UpgradeOpen().  And as with all interactions with the drawing database, you must use a transaction for this.

The following two code snippets are identical.  The oId is an object ID, such as one returned by Editor.GetSelection().  This code simply insert a point to the beginning of the selected polyline, so that it now starts at (0,0).


--- Code: ---using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
    Polyline p = tr.GetObject(oId, OpenMode.ForWrite, false) as Polyline;
    if (p != null)
    {
        p.AddVertexAt(0, new Point2d(), 0, 0, 0);
    }
    tr.Commit();
}

--- End code ---


--- Code: ---using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
    Polyline p = tr.GetObject(oId, OpenMode.ForRead, false) as Polyline;
    if (p != null)
    {
        p.UpgradeOpen();
        p.AddVertexAt(0, new Point2d(), 0, 0, 0);
    }
    tr.Commit();
}

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version