Insert vertex to polyline
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am new to .net environment in cad. I am using autocad 2006 with dotnet 2005.
I have written the following code to insert a new vertex at selected location on polyline.
But it is getting error.
Please help me how to work out this.
[CommandMethod("iv")]
public static void addplyver()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
int chk = 1;
PromptEntityOptions ets = new PromptEntityOptions("\nSelect entity to Insert vertex");
PromptEntityResult ets1 = ed.GetEntity(ets);
if (ets1.Status == PromptStatus.OK)
{
Transaction tr = acCurDb.TransactionManager.StartTransaction();
using (tr)
{
DBObject obj = tr.GetObject(ets1.ObjectId, OpenMode.ForWrite);
Polyline lws = obj as Polyline;
if (lws != null)
{
Point3d pnt1 = ed.Snap("Nea", ets1.PickedPoint);
Plane pl = new Plane(pnt1, lws.Normal);
for (int i = 0; (i <= (lws.NumberOfVertices - 1)); i++)
{
if ((lws.GetDistAtPoint(pnt1) < (lws.GetDistAtPoint(lws.GetPoint3dAt(i)))) && chk != 0)
{
lws.AddVertexAt(i, pnt1.Convert2d(pl), 0, 0, 0);
chk = 0;
}
}
}
tr.Commit();
}
}
}
Thanks in advance,
Kumar.