+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Jan 2008
    Posts
    286

    Default How to get the length of a spline

    Registered forum members do not see this ad.

    Hello: I'm writing a small script in vba and need to get the length of a spline for some calculations. I see that length is not a property of AcadSpline linetype. Does anyone know how I can go about doing this?

    Thanks,
    Proctor

  2. #2
    Super Member CADken's Avatar
    Computer Details
    CADken's Computer Details
    Operating System:
    Microsoft Windows 7 Ultimate
    Computer:
    Toshiba Satellite A135
    CPU:
    Intel Pentium T2080 @ 1.73GHz, 1733 Mhz, 2 Core(s), 2 Logical Processor(s)
    RAM:
    Slot 1: 1GB DDR Slot 2: 1GB DDR
    Primary Storage:
    Toshiba 110GB, Maxtor External HD 120GB
    Monitor:
    Notebook Monitor + 22" NEC AccuSync LCD223wxm
    Using
    AutoCAD 2010
    Join Date
    Jun 2006
    Location
    East Coast - Pennsylvania
    Posts
    828

    Default

    select the spline, type "list" > enter?

    sorry i'm not following your post 100%
    Fireman | Draftsman | Fabricator
    Running Windows 7 with AutoCAD 2010
    the Battalion East Side Pride

  3. #3
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Jan 2008
    Posts
    286

    Default i can see the length of my spline now

    that's great...I love that trick....but, how can I get the length via my vba script (intellisense doesn't have length for spline):


    for my line...I entered:
    Dim MyLine As AcadLine
    MyLineLength = MyLine.Length(intellisense has length listed for line)

    but when I go to do this for my spline:
    Dim MySpline As AcadSpline
    MyLineLength = MySpline. (intellisense doesn't have length listed for spline)

    any ideas..and thanks again for your help.

  4. #4
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Apr 2006
    Location
    Los Angeles
    Posts
    65

    Default

    Google the Curve.cls
    This is a class that uses lisp through vba to access the acad math class.

  5. #5
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,586

    Default

    Try this but dirty method with using of SenCommand
    this worked good for me though
    Take a look at 'GetCurveLength' function in the code

    Code:
    Option Explicit
    
    
    Function TotLen(oSset As AcadSelectionSet) As Double
    Dim oEnt As AcadEntity
    For Each oEnt In oSset
        If TypeOf oEnt Is AcadPolyline Or _
        TypeOf oEnt Is AcadLWPolyline Or _
        TypeOf oEnt Is AcadLine Then
            TotLen = TotLen + oEnt.Length
        ElseIf TypeOf oEnt Is AcadArc Then
            TotLen = TotLen + oEnt.ArcLength
        ElseIf TypeOf oEnt Is AcadCircle Then
            TotLen = TotLen + oEnt.Circumference
        ElseIf TypeOf oEnt Is AcadSpline Then
            TotLen = TotLen + GetCurveLength(oEnt)
        ElseIf TypeOf oEnt Is AcadEllipse Then
            TotLen = TotLen + GetCurveLength(oEnt)
        End If
    Next oEnt
    End Function
    
    Function GetCurveLength(oEnt As AcadEntity) As Double
    Dim sVar
    sVar = 0
    Dim strCom As String
    With ThisDrawing
    .SetVariable "USERR1", sVar
    .SendCommand "(vl-load-com)" & vbCr
    strCom = "(setvar " & Chr(34) & "USERR1" & Chr(34) & Chr(32) & "(vlax-curve-getdistatparam (vlax-ename->vla-object (handent " & Chr(34) & oEnt.Handle & Chr(34) & ")) (vlax-curve-getendparam (vlax-ename->vla-object (handent " & Chr(34) & oEnt.Handle & Chr(34) & ")))))" & vbCr
    .SendCommand strCom
    GetCurveLength = .GetVariable("USERR1")
    End With
    End Function
    
    Sub TryIt()
    Dim oSset As AcadSelectionSet
    Dim oEnt
    Dim fcode(0) As Integer
    Dim fData(0) As Variant
    Dim dxfCode, dxfdata
    Dim i As Integer
    Dim SetName As String
    
    ' create filter
    fcode(0) = 0
    ' include the following entity types:
    ' LINE, LWPOLYLINE, POLYLINE, SPLINE, ARC, CIRCLE, ELLIPSE:
    fData(0) = "*LINE,ARC,CIRCLE,ELLIPSE"
    '
    dxfCode = fcode
    dxfdata = fData
    '
    SetName = "$Total$"
    ' delete all selection sets to make sure that named selection does not exist
              With ThisDrawing.SelectionSets
                   While .Count > 0
                        .Item(0).Delete
                   Wend
              End With
    ' add empty selection into selectionsets collection
    Set oSset = ThisDrawing.SelectionSets.Add(SetName)
    ' select on screen
    oSset.SelectOnScreen dxfCode, dxfdata
    ' display result
    If oSset.Count > 0 Then
    MsgBox CStr(Round(TotLen(oSset), 3)), vbInformation, "Total Length"
    Else
    MsgBox "0 selected, try again"
    End If
    
    End Sub
    ~'J'~

  6. #6
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Jan 2008
    Posts
    286

    Default script on the lisp side?

    thanks fatty:

    It looks like you are calling sub routine:
    GetCurveLength(oEnt As AcadEntity) As Double
    which in turn, passes some vars to a lisp routine.

    is this correct? you wouldn't happen to have the script on the lisp side - would you?

    thanks again,
    Proctor

  7. #7
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,586

    Default

    Hi,
    Not at all. Here it was passed to the command line the
    Lisp expression only (not a sub), which calculates the length of object,
    this line: (vl-load-com) load Visual Lisp (ActiveX) library
    and then it calculates the distance at the end parameter
    of this object, nothing else

    ~'J'~

  8. #8
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Jan 2008
    Posts
    286

    Default It's working!!!

    I get it now...it's working!!!

    Thank you so much for your help...this is great!

    Proctor

  9. #9
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,586

    Default

    Registered forum members do not see this ad.

    Always glad to help
    Cheers

    ~'J'~

Similar Threads

  1. Length of a Spline
    By joykutty in forum AutoCAD General
    Replies: 10
    Last Post: 19th Aug 2008, 06:09 pm
  2. LINE LENGTH
    By goody in forum AutoCAD Beginners' Area
    Replies: 10
    Last Post: 1st Jul 2006, 10:34 am
  3. Wall length
    By luvin_paintball132 in forum AutoCAD General
    Replies: 2
    Last Post: 13th Jun 2006, 12:23 am
  4. Length of a Spline
    By macclad in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 9th Feb 2006, 10:41 pm
  5. How do I measure the length of a spline
    By Lester in forum AutoCAD General
    Replies: 4
    Last Post: 2nd May 2005, 11:07 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts