Getting parameter value

Discussion in 'AutoCAD' started by Jean-Yves, Apr 21, 2004.

  1. Jean-Yves

    Jean-Yves Guest

    Hi all ,

    I'am converting an old lisp function to an Autocad 2002 VBA function .
    When the user has selected polyline(s) my "lisp" function shows the total
    perimeter.

    How can I get the perimeter value in VBA ?

    Thanks in advance .

    Jean-Yves
     
    Jean-Yves, Apr 21, 2004
    #1
  2. Jean-Yves

    Michel Guest

    Hi Jean-Yves,

    A lwpoly (AcadLWPolyline) has a length-property which in this case is the perimeter.

    Michel
     
    Michel, Apr 21, 2004
    #2
  3. Jean-Yves

    Jean-Yves Guest

    Sorry Michel ,

    but the AcadLWPolyline has not length-property !!

    Jean-Yves

    Here is my VB code :
    '****************************
    Public Sub GetPerimeter()
    Dim aPoly As AcadEntity,masel As AcadSelectionSet,mapl As AcadLWPolyline

    Set masel = ThisDrawing.SelectionSets.Add("SELEC")
    masel.SelectOnScreen

    For Each aPoly In ThisDrawing.ActiveSelectionSet
    Set mapl =aPoly
    mapl.Length '<---- this property does not exist !!
    Next
    Set aPoly= Nothing
    masel.Delete

    End Sub
    '****************************
     
    Jean-Yves, Apr 21, 2004
    #3
  4. Jean-Yves

    Kevin Terry Guest

    but the AcadLWPolyline has not length-property !!
    autocad 2004 does have that property.

    in 2002 you need to use something like this (credit goes to Randall Rath for
    the code):
    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
     
    Kevin Terry, Apr 21, 2004
    #4
  5. Jean-Yves

    Jean-Yves Guest

    It's working fine .

    Thanks a lot .

    Jean-Yves
     
    Jean-Yves, Apr 21, 2004
    #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.