• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    matejt
    Posts: 25
    Registered: ‎12-05-2010

    Read vertices of a polyline

    1163 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,

    Please use plain text.
    Member
    Posts: 3
    Registered: ‎08-11-2008

    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

     

    Please use plain text.
    Contributor
    matejt
    Posts: 25
    Registered: ‎12-05-2010

    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,

    Please use plain text.
    *Expert Elite*
    chiefbraincloud
    Posts: 736
    Registered: ‎02-13-2008

    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
    Please use plain text.
    Contributor
    matejt
    Posts: 25
    Registered: ‎12-05-2010

    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

    Please use plain text.