.NET

Reply
Mentor
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 1 of 7

PLine Segments from GetEntity

405 Views, 6 Replies
09-27-2006 09:33 AM
Hi, i'm writing a program in VB .NET which rotates blocks, text, and mtext. the program allows the user to rotate the objects relative to their current rotation, to an absolute angle, and to match an existing object's rotation.

the only problem i'm having currently is matching polyline segments. i am unsure how to get a polyline segment using data from the Editor's GetEntity routine.
It returns a point, and that point should be on or very near to the segment i want, is there a way to figure out which segment they selected?
Active Contributor
38 Posts
0 Kudos
Registered: ‎08-31-2006
Post 2 of 7

Re: PLine Segments from GetEntity

09-29-2006 10:47 AM in reply to: MarkPendergraft
This may not be the most efficient approach, but if I understand your question then you can explode the polyline, which creates a collection of new objects, and iterate that collection getting the closest distance from each of the new objects to the point selected. The one with the closest distance is the segment you are looking for. Of course this will leave you with a problem in case the user selected a point that is at the exact same distance from two or more segments (eg. osnap is on and the user clicks on an endpoint inside the polyline), but it might work anyway.
Mentor
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 3 of 7

Re: PLine Segments from GetEntity

09-29-2006 10:54 AM in reply to: MarkPendergraft
thanks for the response.
but i have come to the conclusion that rotating to a polyline would be too much work, for just a little added functionality. Its a shame there isn't a method that tells you where they picked on the Polyline. Seems to me like there should be.
Oh, well

Thanks again for offering up ideas though.
Valued Contributor
67 Posts
0 Kudos
Registered: ‎09-12-2006
Post 4 of 7

Re: PLine Segments from GetEntity

09-29-2006 11:22 PM in reply to: MarkPendergraft
If you're trying to get the startpoint and endpoint of the segment you pick, here's a way to do it:


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;
}
}
*Tony Tanzillo
Post 5 of 7

Re: PLine Segments from GetEntity

09-30-2006 09:55 AM in reply to: MarkPendergraft
>> Its a shame there isn't a method that tells you where they picked on the Polyline.

Who said there wasn't?

Try Editor.GetNestedEntity()

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5345756@discussion.autodesk.com...
thanks for the response.
but i have come to the conclusion that rotating to a polyline would be too much work, for just a little added functionality. Its a shame there isn't a method that tells you where they picked on the Polyline. Seems to me like there should be.
Oh, well

Thanks again for offering up ideas though.
Mentor
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 6 of 7

Re: PLine Segments from GetEntity

09-30-2006 10:36 AM in reply to: MarkPendergraft
Thanks guys,
Maybe i gave up hope a little too quick there. I made the jump from VBA to .NET, and the COM libraries are child's play compared to the Managed API. Guess i feel like i'm in over my head a little bit. Oh, well. Thats the way i learn best.

Thanks again, i will explore both methods and see which one i like best.
Mentor
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 7 of 7

Re: PLine Segments from GetEntity

09-30-2006 02:54 PM in reply to: MarkPendergraft
Hey, thanks again guys. I swear i combed through the methods and properties of the polyline object 100 times, and not once did i see the onSegmentAt method. How frustrating, i feel like an idiot.

anyways, once i saw this method, i didn't even need to use the GetNestedEntity() method.

Here is a snippet of what i came up with, I hate to get a good answer and not post the resulting code, so here it is, i have already used the Editor.GetEntity() method to get a variety of different entities, so here is the if.... then clause which contains all of the code for getting the polyline segment the user picked.


ElseIf TypeOf gotEnt Is Polyline Then
pLin = gotEnt
Dim pLinPnt As Point2d= pLin.GetClosestPointTo(prEntRes.PickedPoint, True).Convert2d(wPlane)
Dim seg As Integer
For seg = 0 To (pLin.NumberOfVertices - 2)
If pLin.OnSegmentAt(seg, pLinPnt, 0.0) Then
Exit For
End If
Next
If pLin.GetSegmentType(seg) = SegmentType.Line Then
Dim plLin As LineSegment3d = pLin.GetLineSegmentAt(seg)
Vect = plLin.EndPoint - plLin.StartPoint
Rotation = Vect.AngleOnPlane(wPlane)
If Rotation > (Math.PI * 0.5) And Rotation < (Math.PI * 1.5) Then Rotation = Rotation - Math.PI
ElseIf pLin.GetSegmentType(seg) = SegmentType.Arc Then
Dim plArc As CircularArc3d = pLin.GetArcSegmentAt(seg)
Vect = prEntRes.PickedPoint - plArc.Center
Rotation = (Vect.AngleOnPlane(wPlane) + (PI * 0.5))
If Rotation > (Math.PI * 0.5) And Rotation < (Math.PI * 1.5) Then Rotation = Rotation - Math.PI
End If
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!