Length of a lwpolyline

Discussion in 'AutoCAD' started by DRW1975, Dec 16, 2004.

  1. DRW1975

    DRW1975 Guest

    is there a way to get the length of an lwpolyline without actually calculating it based on coordinates of each point?
    (like how .area works)

    DRW
     
    DRW1975, Dec 16, 2004
    #1
  2. DRW1975

    fantum Guest

    You don't specify a version but the current one exposes a Length property for lwp's.
     
    fantum, Dec 16, 2004
    #2
  3. DRW1975

    DRW1975 Guest

    I am using 2002 here at work, and it doesn't seem to exist... I will look into it in 2005 version.

    If I have to, I will code a routine to determine the length of a lwp, it would not be long, I was just wondering if there might be a one-line short cut.

    DRW
     
    DRW1975, Dec 16, 2004
    #3
  4. The Length property was added in 2004 (I believe).

    --
    R. Robert Bell


    is there a way to get the length of an lwpolyline without actually
    calculating it based on coordinates of each point?
    (like how .area works)

    DRW
     
    R. Robert Bell, Dec 17, 2004
    #4
  5. DRW1975

    Kevin Terry Guest

    Here's a function that'll do this for you:

    I'm pretty sure I got this from Randall Rath originally...

    ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    .. . . . . . . . . . .
    '
    'Returns length of polyline passed in
    '
    'Passed variables:
    'objPline = polyline object
    '
    Public Function PlineLenEX(objPline As AcadLWPolyline) As Double
    Dim intVCnt As Integer
    Dim varCords As Variant
    Dim varVert As Variant
    Dim varCord As Variant
    Dim varNext As Variant
    Dim intCrdCnt As Integer
    Dim dblTemp As Double
    Dim dblArc As Double
    Dim dblAng As Double
    Dim dblChord As Double
    Dim dblInclAng As Double
    Dim dblRad As Double
    Dim intDiv As Integer
    On Error GoTo Err_Control
    intDiv = 2
    varCords = objPline.Coordinates
    For Each varVert In varCords
    intVCnt = intVCnt + 1
    Next
    For intCrdCnt = 0 To intVCnt / intDiv - 1
    If intCrdCnt < intVCnt / intDiv - 1 Then
    varCord = objPline.Coordinate(intCrdCnt)
    varNext = objPline.Coordinate(intCrdCnt + 1)
    ElseIf objPline.Closed Then
    varCord = objPline.Coordinate(intCrdCnt)
    varNext = objPline.Coordinate(0)
    Else
    Exit For
    End If
    If objPline.GetBulge(intCrdCnt) = 0 Then
    'computes a simple Pythagorean length
    dblTemp = dblTemp + Sqr((Sqr(((varCord(0) - _
    varNext(0)) ^ 2) + ((varCord(1) - varNext(1)) ^ 2)) ^ 2))
    Else
    'If there is a bulge we need to get an arc length
    dblChord = Sqr((Sqr(((varCord(0) - varNext(0)) ^ 2) _
    + ((varCord(1) - varNext(1)) ^ 2)) ^ 2))
    'Bulge is the tangent of 1/4 of the included angle between
    'vertices. So we reverse the process...
    dblInclAng = Atn(Abs(objPline.GetBulge(intCrdCnt))) * 4
    dblAng = (dblInclAng / 2) - ((Atn(1) * 4) / 2)
    dblRad = (dblChord / 2) / (Cos(dblAng))
    dblArc = dblInclAng * dblRad
    dblTemp = dblTemp + dblArc
    End If
    'End If
    Next
    PlineLenEX = dblTemp
    Exit_Here:
    Exit Function
    Err_Control:
    Select Case Err.Number
    Case Else
    MsgBox Err.Description
    Err.Clear
    Resume Exit_Here
    End Select
    End Function


    Kevin

    would not be long, I was just wondering if there might be a one-line short
    cut.
     
    Kevin Terry, Jan 5, 2005
    #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.