我正在尝试通过 AutoCAD .Net API 向现有闭合多段线插入一个新顶点。
我有一种将顶点插入折线的方法。但这不适用于下图所示情况的闭合多段线。如果该点位于折线的最后一条边上,则代码将失败。有人可以看到问题所在吗?
public void AddVertexOnPolyline(Point3d addPoint,Polyline editPolyline)
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Editor pEditor = acDoc.Editor;
int chk = 1;
try
{
for (int i = 0; (i <= (editPolyline.NumberOfVertices - 1)); i++)
{
double dist1 = editPolyline.GetDistAtPoint(addPoint);
double dist2 = editPolyline.GetDistAtPoint(editPolyline.GetPoint3dAt(i));
if ((editPolyline.GetDistAtPoint(addPoint) < (editPolyline.GetDistAtPoint(editPolyline.GetPoint3dAt(i)))) && chk != 0)
{
Point2d pnt2 = new Point2d(addPoint.X, addPoint.Y);
editPolyline.AddVertexAt(i, pnt2, 0, 0, 0);
chk = 0;
break;
}
}
}
catch (System.Exception ex)
{
throw;
}
}
注意:我也在 Autodesk 论坛上发布了它