Is possible to change the startpoint of a polyline?
eg:
Polyline lwp = obj as Polyline;
int vn = lwp.NumberOfVertices;
for (int i = 0; i < vn; i++)
{
SegmentType sg = lwp.GetSegmentType(i);
}
...
lwp.StartPoint = lwp.GetArcSegmentAt(1).StartPoint;
Solved! Go to Solution.
I tried without success:
Point3d nextpoint = lwp.GetArcSegmentAt(1).StartPoint;
lwp.SetPointAt(0, new Point2d(nextpoint.X, nextpoint.Y));
because the polyline change shape.
You're trying to set the start point to the second vertex.
You'll have to explain in more detail what you're trying to do.
I've a closed polyline composed by some Arc and Line as in 1.dwg
This polyline has a startpoint at 41.4033981995461,46.6236763815663 (startpoint of the first segment) that I need to change in 43.8777100135197,46.8401506153171 (startpoint of the second segment) before cicllyng with:
int vn = lwp.NumberOfVertices;
for (int i = 0; i < vn; i++)
{
SegmentType sg = lwp.GetSegmentType(i);
...
}
Isn't it obvious that if you want to change the start point of the first
segment to be the start point of the second segment, what you
actually are doing is deleting the first segment/vertex?
Sorry, I really can't figure out what it is you're trying to do.
Perhaps posting a file with the 'before' and 'after' might help.
As attached files before.dwg and after.dwg the first segment of the polyline is different.
My question is: how can I do this programmatically in autocad .net?
The only difference I see is that the first vertex is offset by one
vertex in one of the two polylines.
To do this via the API, you either delete the last vertex and
insert it at the start, or delete the first vertex and insert it
at the end.
No, the last vertex is not the first vertex. If a polylline is closed, it
merely means that there is a segment connecting the first and last
vertices. Perhaps you are confusing vertices with the segments
that connect them.
Sorry, I don't have time to write the code for you.
Ok, now I understand:
int vn = lwp.NumberOfVertices;
lwp.RemoveVertexAt(0);
lwp.AddVertexAt(vn - 1, new Point2d(X, Y), 0, 0, 0);
where Point2d(X, Y) is the StartPoint of the Segment at index = 1
Many thanks