+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Full Member
    Using
    Map 3D 2005
    Join Date
    Dec 2008
    Posts
    33

    Default VBA code for length of selected line

    Registered forum members do not see this ad.

    Hi all,

    I need a VBA code for finding the length of a selected line/polyline..

    i have the code for selectonscreen
    and for length again object.length can be used

    but somehow i m not being able to integrated these two to get the
    length of my selected line.

    Please Help!

    Regards,
    Priyanka

  2. #2
    Super Member SEANT's Avatar
    Using
    Mechanical 2009
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,442

    Default

    This example shows an alternative method for isolating lines and polylines. The method employs a “Filter” to a select on screen call. The example also shows how to cast each entity to it’s proper type before querying the .Length property.

    Note: some object properties are available while still cast only as a general AcadEntity. Some, however, are not. Casting the entity as the more specific type allows full access. And, as an additional note, Autodesk has built in a bit of confusion with the various names given to polylines in the different context.


    Code:
    Sub GetLengths()
    Dim SOS As AcadSelectionSet
    Dim objSS As AcadSelectionSet
    Dim intCode(0) As Integer
    Dim varData(0) As Variant
    Dim objEnt As AcadEntity
    Dim entLine As AcadLine
    Dim entPoly As AcadPolyline
    Dim entLWPoly As AcadLWPolyline
       For Each SOS In ThisDrawing.SelectionSets
          If SOS.Name = "MySS" Then
             ThisDrawing.SelectionSets("MySS").Delete
          Exit For
          End If
       Next
       intCode(0) = 0: varData(0) = "LINE,POLYLINE,LWPOLYLINE"
       ThisDrawing.SelectionSets.Add ("MySS")
       Set objSS = ThisDrawing.SelectionSets("MySS")
       objSS.SelectOnScreen intCode, varData
       
       
       If objSS.Count < 1 Then
          MsgBox "No lines and polylines selected!"
       Exit Sub
       End If
       
       For Each objEnt In objSS
          Select Case objEnt.ObjectName
          Case "AcDbLine"
             Set entLine = objEnt
             MsgBox "Line is " & entLine.Length & " units long."
          Case "AcDb2dPolyline"
             Set entPoly = objEnt
             MsgBox "Polyline is " & entPoly.Length & " units long."
          Case "AcDbPolyline"
             Set entLWPoly = objEnt
             MsgBox "LightWeight Polyline is " & entLWPoly.Length & " units long."
          End Select
       Next
    
    End Sub

  3. #3
    Full Member
    Using
    Map 3D 2005
    Join Date
    Dec 2008
    Posts
    33

    Default

    Hey Thanks,

    This was exactly what I wanted..

    I was using the following code:

    '*******************
    Dim line As AcadLine
    Dim block As AcadBlockReference
    Dim a As String


    On Error Resume Next

    ThisDrawing.SelectionSets("TempSSet").Delete
    Set objSelectionSet = ThisDrawing.SelectionSets.Add("TempSSet")
    'ask user to pick entities on the screen
    objSelectionSet.SelectOnScreen
    'change the highlight status of each entity selected

    For Each line In objSelectionSet

    MsgBox line.length

    Next

    objSelectionSet.Delete

    '***********

    But i really required such filters.Thanks a lot

    Regards,
    Priyanka

Similar Threads

  1. Need a code lisp sum the length of line, pline, arc..
    By Nad SK in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 4th Dec 2008, 07:53 am
  2. Line Display when selected problem
    By clubef9 in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 8th Feb 2008, 06:19 pm
  3. LINE LENGTH
    By goody in forum AutoCAD Beginners' Area
    Replies: 10
    Last Post: 1st Jul 2006, 10:34 am
  4. (code) rotate (M)TEXT based on selected entity
    By Mark Thomas in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 7th Dec 2004, 05:47 pm
  5. Line Length
    By CherylC in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 30th Mar 2003, 11:54 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