Length Property of an AcadPolyline ?

Discussion in 'AutoCAD' started by CGSH, Jul 1, 2003.

  1. CGSH

    CGSH Guest

    How can I retrive the length of a AcadPolyline Object ?
    There is no Lenght properties as for AcadLine object.

    Regards
    cg
     
    CGSH, Jul 1, 2003
    #1
  2. CGSH

    joesu Guest

    Here ya go.

    Joe
    --

    Public Function LengthOfPolyline() As Double Dim Entity As AcadEntity Dim Point As Variant Dim Pline As AcadLWPolyline Dim ExplodedObjects As Variant

    On Error Resume Next

    ThisDrawing.Utility.GetEntity Entity, Point, "Select polyline"   'nothing was selected   If Entity Is Nothing Then Exit Function

    If Entity.ObjectName <> "AcDbPolyline" Then Exit Function

    If TypeOf Entity Is AcadLWPolyline Then     'cast Entity to Polyline proper     Set Pline = Entity

    ExplodedObjects = Pline.Explode

    'iterate through the exploded objects     Dim Index As Integer     Dim Perimeter As Double     Dim Line As AcadLine

    For Index = 0 To UBound(ExplodedObjects)       Perimeter = Perimeter + ExplodedObjects(Index).Length       Set Line = ExplodedObjects(Index)       Line.Delete     Next Index   End If

    'return the length of the polyline   LengthOfPolyline = Perimeter End Function

    Public Sub Test()   MsgBox "Length of Polyline is " & LengthOfPolyline, vbOKOnly, "Polyline length" End Sub
     
    joesu, Jul 1, 2003
    #2
  3. CGSH

    Jürg Menzi Guest

    CGSH

    This sample works also with 'bulged' Plines...

    Public Function GetPolylineLength(CurObj As AcadEntity) As Double

    Dim ExpObj As Variant
    Dim CurEnt As AcadEntity
    Dim CurLgt As Double
    Dim EntCnt As Integer

    ExpObj = CurObj.Explode
    For EntCnt = LBound(ExpObj) To UBound(ExpObj)
    Set CurEnt = ExpObj(EntCnt)
    With CurEnt
    Select Case .ObjectName
    Case "AcDbLine
    CurLgt = CurLgt + .Length
    Case "AcDbArc"
    CurLgt = CurLgt + .ArcLength
    End Select
    .Delete
    End With
    Next EntCnt

    GetPolylineLength = CurLgt

    End Function

    Cheers
     
    Jürg Menzi, Jul 1, 2003
    #3
  4. CGSH

    CGSH Guest

    Thank You !
     
    CGSH, Jul 2, 2003
    #4
  5. CGSH

    CGSH Guest

    Thank You !
     
    CGSH, Jul 2, 2003
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.