Community
Point3d start, end;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptNestedEntityOptions nestedOptions = new PromptNestedEntityOptions("Select side:");
nestedOptions.AllowNone = false;
PromptNestedEntityResult nestedResults = ed.GetNestedEntity(nestedOptions);
if (nestedResults.Status != PromptStatus.OK) throw new Autodesk.AutoCAD.Runtime.Exception();
DBObject nestedObject = nestedResults.ObjectId.GetObject(OpenMode.ForRead);
if (nestedObject.GetType() == typeof(Polyline))
{
Polyline plineEntity = (Polyline)nestedObject;
Point2d searchPoint = plineEntity.GetClosestPointTo(nestedResults.PickedPoint, false).Add(plineEntity.StartPoint.GetAsVector()).Convert2d(plineEntity.GetPlane());
int segmentIndex;
for (segmentIndex = 0; segmentIndex < plineEntity.NumberOfVertices - 1; segmentIndex++)
if (plineEntity.OnSegmentAt(segmentIndex, searchPoint, 0.0)) break;
LineSegment3d lineSegment = plineEntity.GetLineSegmentAt(segmentIndex);
start = lineSegment.StartPoint;
end = lineSegment.EndPoint;
}
else if (nestedObject.GetType() == typeof(PolylineVertex3d))
{
PolylineVertex3d pvertex = (PolylineVertex3d)nestedObject;
start = pvertex.Position;
Polyline3d parent = (Polyline3d)pvertex.OwnerId.GetObject(OpenMode.ForRead);
end = parent.StartPoint;
bool found = false;
foreach (ObjectId vertexId in parent)
{
PolylineVertex3d vertex = (PolylineVertex3d)vertexId.GetObject(OpenMode.ForRead);
if (found) { end = vertex.Position; break; }
if (vertex.Equals(pvertex)) found = true;
}
}
Can't find what you're looking for? Ask the community or share your knowledge.