vba calculate length of line selected help

Discussion in 'AutoCAD' started by johnbortoli, Mar 4, 2005.

  1. johnbortoli

    johnbortoli Guest

    I have avba project i am working on which asks the user to select apolyline on the drawing. The code then gets the length of the line but rturns to abiut 6 decimal places.
    Question 1.
    How do i get it to return the length to 2 decimal places only?
    Question 2.
    If the user selects anumber (ie 2, 3, 4 etc) from a combobox on a user form in the project, how do i get the length of the line multiplied by the selected number?
    I have listed the code i have at present below. I think that is all.
    Regards JohnB
    '------------------------------------------------------------------------------------

    Public Sub AddTendon()
    Dim intFilterType(0 To 0) As Integer
    Dim varFilterData(0 To 0) As Variant
    Dim objSelectionSet As AcadSelectionSet

    For Each objSelectionSet In ThisDrawing.SelectionSets
    If objSelectionSet.Name = "AddTendon" Then
    objSelectionSet.Delete
    Exit For
    End If
    Next objSelectionSet

    Set objSelectionSet = ThisDrawing.SelectionSets.Add("AddTendon")

    ThisDrawing.Utility.prompt "Select a tendon..." & vbCrLf

    intFilterType(0) = 0
    varFilterData(0) = "LWPOLYLINE"
    objSelectionSet.SelectOnScreen intFilterType, varFilterData

    If objSelectionSet.Count > 0 Then
    strTendonLength = CalcTendonLength(objSelectionSet(0))
    frmAddTendon.Show
    Else
    Exit Sub
    End If
    End Sub
    '------------------------------------------------------------------------------------

    Public Function CalcTendonLength(objPolyLine As AcadLWPolyline) As Double
    Dim varEntities As Variant
    Dim dblLength As Double
    Dim intIndex As Integer

    dblLength = 0#

    varEntities = objPolyLine.Explode
    For intIndex = LBound(varEntities) To UBound(varEntities)
    If TypeOf varEntities(intIndex) Is AcadLine Then
    dblLength = dblLength + varEntities(intIndex).Length
    ElseIf TypeOf varEntities(intIndex) Is AcadArc Then
    dblLength = dblLength + varEntities(intIndex).ArcLength
    End If
    varEntities(intIndex).Delete
    Next intIndex

    CalcTendonLength = dblLength
    End Function

    '------------------------------------------------------------------------------------
     
    johnbortoli, Mar 4, 2005
    #1
  2. johnbortoli

    MP Guest

    apolyline on the drawing. The code then gets the length of the line but
    rturns to abiut 6 decimal places.
    Debug.Print Round(25.345243985744, 2)
    or if you're dealing with strings look at the Format function

    hth

    form in the project, how do i get the length of the line multiplied by the
    selected number?

    now I'm not sure what you're exactly asking cause I'm sure you know...
    dLen = 25.25
    lNum = 4
    dRes = dLen * lNum
    so I think i'm missing something in your question...


    Mark
     
    MP, Mar 4, 2005
    #2
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.