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

get all verticies of a 2dPolyline

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
482 Views, 2 Replies

get all verticies of a 2dPolyline

Is there a property or method to do this?

If not is there a round-about way?

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Hi ,

With below code you can find all vertices of a 2D polyline.

 

  <CommandMethod("GV")> Public Sub GetVertice()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Select a polyline:")
        Dim per As PromptEntityResult = ed.GetEntity(peo)
        If per.Status <> PromptStatus.OK Then
            Return
        End If
        Using tx As Transaction = db.TransactionManager.StartTransaction()
            Dim pl As Polyline = TryCast(tx.GetObject(per.ObjectId, OpenMode.ForRead), Polyline)
            For v = 0 To pl.NumberOfVertices - 1
                MsgBox(pl.GetPoint2dAt(v).ToString)
            Next
        End Using
    End Sub

 

Message 3 of 3
_gile
in reply to: Anonymous

Hi,

 

If you're talking about (heavy) Polyline2d instance, you can use this extension method.

 

    public static class Polyline2dExtensions
    {
        /// <summary>
        /// Gets the vertices list of the polyline 2d.
        /// </summary>
        /// <param name="pl">The instance to which the method applies.</param>
        /// <returns>The vertices list.</returns>
        /// <exception cref="Autodesk.AutoCAD.Runtime.Exception">
        /// eNoActiveTransactions is thrown if the method is not called form a Transaction.</exception>
        public static List<Vertex2d> GetVertices(this Polyline2d pl)
        {
            Transaction tr = pl.Database.TransactionManager.TopTransaction;
            if (tr == null)
                throw new AcRx.Exception(AcRx.ErrorStatus.NoActiveTransactions);

            List<Vertex2d> vertices = new List<Vertex2d>();
            foreach (ObjectId id in pl)
            {
                Vertex2d vx = (Vertex2d)tr.GetObject(id, OpenMode.ForRead);
                if (vx.VertexType != Vertex2dType.SplineControlVertex)
                    vertices.Add(vx);
            }
            return vertices;
        }
    }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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