.NET

.NET

Reply
Valued Contributor
jankoezb
Posts: 51
Registered: ‎10-31-2005
Message 1 of 2 (75 Views)

Exposing point collections from instantiated polylines

75 Views, 1 Replies
10-31-2005 01:38 PM
How can I expose the collection of points used to generate a simple polyline? It seems unbelievable to me that you pass a point collection as a parameter to the polyline constructor (in one of the constructor overloads) and yet you cannot access it afterwards, through a property or a method of the polyline class !? Does anyone have a clue about this one ?

Janko Jerinic
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 2 of 2 (75 Views)

Re: Exposing point collections from instantiated polylines

10-31-2005 02:14 PM in reply to: jankoezb
A simple point collection would not work on a 2d polyline, and since these are simple wrappers around ObjectARX classes, you are in the same boat.

Here is some code to get at pline2d and 3d, the 2d code generates an offset polyline and gets the data.



_
Public Shared Sub TestPline()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()

Try
Dim prEnt As New PromptEntityOptions("Select a polyline:")
Dim prEntRes As PromptEntityResult = editor.GetEntity(prEnt)
If prEntRes.Status PromptStatus.OK Then Return

Dim id As ObjectId = prEntRes.ObjectId
' get input polyline
Dim ent As Entity = DirectCast(trans.GetObject(id, OpenMode.ForRead), Entity)
Dim pl As Polyline = DirectCast(ent, Polyline)

Dim curves As DBObjectCollection = pl.GetOffsetCurves(2.0)
Dim i As Integer
Dim s As String
For i = 0 To curves.Count - 1
Dim newPl As Polyline = DirectCast(curves.Item(i), Polyline)
Dim isNew As Boolean = newPl.IsNewObject
Dim numSegs As Integer = newPl.NumberOfVertices
If newPl.Closed = False Then numSegs -= 1
Dim j As Integer
For j = 0 To numSegs - 1
Dim segType As SegmentType = newPl.GetSegmentType(j)
If segType = SegmentType.Line Then
Dim seg2 As LineSegment2d
Dim seg3 As LineSegment3d
seg2 = newPl.GetLineSegment2dAt(j)
seg3 = newPl.GetLineSegmentAt(j)
ElseIf segType = SegmentType.Arc Then
Dim a2 As CircularArc2d = newPl.GetArcSegment2dAt(j)
Dim a3 As CircularArc3d = newPl.GetArcSegmentAt(j)
End If
Next
Next
curves.Dispose()

'MsgBox(s)


trans.Commit()
Catch ex As Exception
trans.Abort()
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try

End Sub

_
Public Shared Sub TestPline3d()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()

Try
Dim prEnt As New PromptEntityOptions("Select a 3d polyline:")
Dim prEntRes As PromptEntityResult = editor.GetEntity(prEnt)
If prEntRes.Status PromptStatus.OK Then Return

Dim id As ObjectId = prEntRes.ObjectId
' get input polyline
Dim ent As Entity = DirectCast(trans.GetObject(id, OpenMode.ForRead), Entity)
Dim pl As Polyline3d = DirectCast(ent, Polyline3d)
Dim c As Curve = DirectCast(pl, Curve)

' the magic trick is first line segment on 3dpoly is 0.0 to 1.0,
' 2nd line seg is 1.0 to 2.0, rinse and repeat
Dim sp As Double = c.StartParam
Dim ep As Double = c.EndParam
Dim outPts As String
Dim p As Double

For p = sp To ep Step 1.0
Dim pt As Point3d = c.GetPointAtParameter(p)
outPts &= String.Format(" {0},{1},{2} ", pt.X, pt.Y, pt.Z) & vbCrLf
Next

MsgBox(outPts)


trans.Commit()
Catch ex As Exception
trans.Abort()
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try

End Sub
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.