Find Polyline Length with Autolisp

Discussion in 'AutoCAD' started by Bill H, Aug 15, 2005.

  1. Bill H

    Bill H Guest

    I want to be able to find th length of simple 2d polylines made up of lines
    and arcs.
    I can LIST it and the value shows up, or I can highlight it and the value
    shows up in the properties box.
    But I can't figure out how to use Autolisp to find this value.
    Is it stored or is it calculated each time I list the polyline?
     
    Bill H, Aug 15, 2005
    #1
  2. Bill H

    Dr Fleau Guest

    True to internet form and protocol, "Bill H" <>
    said:

    -->I want to be able to find th length of simple 2d polylines made up
    of lines
    -->and arcs.
    -->I can LIST it and the value shows up, or I can highlight it and the
    value
    -->shows up in the properties box.
    -->But I can't figure out how to use Autolisp to find this value.
    -->Is it stored or is it calculated each time I list the polyline?
    -->

    Yo.
    Cut'N'Paste this snippet into a new text file, rename the extension to
    ".lsp" and save it in a directory where ACAD will find it. Load using
    "ap" in ACAD (application load) and type "Develop" to use. I created a
    button that calls it whenever I need it.

    What it does, it lets you select all the lines and arcs you want to
    measure, and indicates the total length in a message window. It's
    kinda hard to miss.
    If you want to ditch the message box in favor of a standard
    CommandLine text, change the "alert" below for "princ", and add an
    extra "(princ)" after the OSMODE change code.

    Note: will not work on ellipses, plines or anything other than lines
    or arcs.

    Free of charge, sold as seen.

    Dr Fleau


    (defun c:develop (/ iter devel $a total data1
    stpt endpt distl strad endrad distr
    )
    (setvar "osmode" 0)
    (setq $a nil
    iter 0
    devel 0.0
    stpt nil
    endpt nil
    strad 0.0
    endrad 0.0
    rad 0.0
    distl 0.0
    distr 0.0
    total 0.0
    devel 0.0
    )
    (setq $a (ssget))
    (setq total (sslength $a))
    (while (< 0 total)
    (progn
    (setq data1 (cdr (entget (ssname $a iter))))
    (cond
    ((= (cdr (assoc 0 data1)) "LINE")
    (Progn
    (setq
    stpt
    (cdr (assoc 10 data1))
    endpt
    (cdr (assoc 11 data1))
    )
    (setq distl (abs (distance stpt endpt)))
    (setq devel (+ devel distl))
    ) ;_END PROGN
    ) ;_END COND1
    ((= (cdr (assoc 0 data1)) "ARC")
    (Progn
    (setq
    strad
    (cdr (assoc 50 data1))
    endrad
    (cdr (assoc 51 data1))
    rad
    (cdr (assoc 40 data1))
    )
    (cond
    ((> endrad strad)
    (setq distr (* rad (- endrad strad)))
    )
    ((setq distr (* rad (+ endrad (- (* 2 pi) strad))))
    )
    (t nil)
    ) ;_end COND
    (setq devel (+ devel distr))
    ) ;_END PROGN
    ) ;_END COND2
    (T nil)
    ) ;_END COND
    (setq iter (+ 1 iter))
    (setq total (- total 1))
    ) ;_END PROGN
    ) ;_END WHILE
    (alert (strcat "Total length : " (rtos devel) " units "))
    (setq $a nil)
    (setvar "osmode" 0)
    ) ;_end DEFUN DEVELOP
     
    Dr Fleau, Aug 16, 2005
    #2
  3. Bill H

    William Ogle Guest

    The value is stored in the system variable "PERIMETER", so after using list,
    you can access it using (getvar "perimeter"). It has the disadvantage of
    needing to use the command line, but it does accurately figure arcs, etc.

    Does anyone know how to set the perimeter variable without using the command
    prompt?
     
    William Ogle, Aug 19, 2005
    #3
  4. Bill H

    Bill H Guest

    I guess I should have mentioned that I want the text to update when I
    stretch the polyline.
    Kinda makes it a hores of a different color.
    It's a simple polyline with 2 straight segments and a fixed-radius fillet in
    the center.
    I will probably need to write something that calculates and totals the
    segment lengths.
    Then I will need to create some type of object or application to make it
    happen.

    Thanks for the routine..I'm sure it will save me lots of time figuring the
    fillet length, and it is appreciated.

    Bill
     
    Bill H, Aug 24, 2005
    #4
  5. Bill H

    Bill H Guest

    Thanks.
    I did not know that.
    It is nice to know.
    If nothing else, I can pick the pline, then pick the text, and have Autolisp
    LIST the line and update the text with the perimeter value.
    That gets me better than half way to whgere I am trying to go.
     
    Bill H, Aug 24, 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.