.NET

Reply
Contributor
matejt
Posts: 25
Registered: ‎12-05-2010
Message 1 of 5 (2,070 Views)

Read vertices of a polyline

2070 Views, 4 Replies
01-25-2011 05:57 AM

Hi,

I need to read all vertices of a polyline and extract coordinates.

Could you please tell me how to do that in VB.NET?

Thanx,

Member
asim777
Posts: 3
Registered: ‎08-11-2008
Message 2 of 5 (2,067 Views)

Re: Read vertices of a polyline

01-25-2011 06:12 AM in reply to: matejt

 

VB.Net code -  
 Public Shared Function getAllVertices(ByVal ent As Polyline) As Point2dCollection
        Dim verCollection As Point2dCollection = New Point2dCollection()
        Dim vertex As Point2d
        Dim i As Integer = 0
        For i = 0 To ent.NumberOfVertices - 1
            vertex = ent.GetPoint2dAt(i)
            verCollection.Add(vertex)
        Next
        Return verCollection
    End Function

    Public Shared Function getAllVertices(ByVal ent As Polyline) As Point2dCollection        Dim verCollection As Point2dCollection = New Point2dCollection()        Dim vertex As Point2d        Dim i As Integer = 0        For i = 0 To ent.NumberOfVertices - 1            vertex = ent.GetPoint2dAt(i)            verCollection.Add(vertex)        Next        Return verCollection    End Function

 

Contributor
matejt
Posts: 25
Registered: ‎12-05-2010
Message 3 of 5 (2,033 Views)

Re: Read vertices of a polyline

01-26-2011 01:26 AM in reply to: asim777

Thank you for the response.

In fact, I need to read vertices of 3D Polylines and have problems finding NumberOfVertices property...

Could you suggest me in this regard? Thanx,

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 4 of 5 (1,994 Views)

Re: Read vertices of a polyline

01-27-2011 05:24 PM in reply to: matejt

Depending on circumstances, in the past I have used Polyline3d.GetStretchPoints.  You pass it an empty Point3dCollection and it fills the collection.

 

That said, it doesn't work when the polyline is not db resident, and I'm not sure what it would do if the Polyline was not type SimplePoly, so, this is another way.

 

For I as Integer = 0 to Poly3d.EndParam

      PointCol.Add (Poly3d.GetPointAtParameter(I))

Next I 

 

 

Dave O.                                                                  Sig-Logos32.png
Contributor
matejt
Posts: 25
Registered: ‎12-05-2010
Message 5 of 5 (1,767 Views)

Re: Read vertices of a polyline

04-12-2011 04:32 AM in reply to: matejt

This is a way to do it:

 

Sub Read3DPolyline(ByVal poly3d As Polyline3d)
        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

            Dim vId As ObjectId
            For Each vId In poly3d
                Dim v3d As PolylineVertex3d = acTrans.GetObject(vId, OpenMode.ForRead)
                acDoc.Editor.WriteMessage(vbCrLf + v3d.Position.ToString())
            Next
            acTrans.Commit()
        End Using
    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.