.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PLine Segments from GetEntity

6 REPLIES 6
Reply
Message 1 of 7
MarkPendergraft
1014 Views, 6 Replies

PLine Segments from GetEntity

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?
6 REPLIES 6
Message 2 of 7

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.
Message 3 of 7

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.
Message 4 of 7

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;
}
}
Message 5 of 7
Anonymous
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.
Message 6 of 7

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.
Message 7 of 7

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost