See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Line Length

  1. #1
    Member
    Join Date
    2009-02
    Posts
    40
    Login to Give a bone
    0

    Default Line Length

    I work in the civil engineering and the type of CAD work that we do results in us showing a polyline for work area. This polyline crosses several pages and we show a box with the specific footage on each page. This line is never straight and turns often, resulting in several angles that just doing a "getpoint" LISP command won't work.

    I am looking for 3 different options of a LISP.

    1. A Lisp where I can select the polyline and it will put the length of that line into a variable setting, to later be inserted into an attributed text line. (That last part I can do, it's just getting the line footage I need)

    2. A Lisp that allows me to getpoint by selecting two ends of the line and then select the line. This one is a bit complicated since it would need to factor in the footage between those two points if the line turns or angles. Then it would put that number into a variable to later be inserted into an attributed text line. (I'm not sure if this one can be done)

    3. A Lisp that would allow me to select multiple polylines, it will add those footage's and put the total into a variable to later be inserted into an attributed text line.

    These do not have to be combined into one LISP, I am hoping to get create these separately.

    I am newer to writing LISP. I have written a few small files, but nothing major. Any help on doing this is greatly appreciated.

    Thanks!

  2. #2
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Line Length

    This should get you started. Question two is entirely possible, it's just too late to work on anything else...

    Code:
    ;;; Total length of selected Arcs, Lines & LWPolylines
    ;;; Value is printed to screen and stored in system variable "UserS5"
    ;;; Alan J. Thompson, 03.20.10
    (defun c:TL (/ #SS #Len)
      (vl-load-com)
      (princ "\nSelect Arc, Line, LWPolyline object(s) to calculate total length: ")
      (cond
        ((setq #SS (ssget '((0 . "ARC,LINE,LWPOLYLINE"))))
         (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
         (setq #Len 0.)
         (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
           (cond ((eq (vla-get-objectname x) "AcDbArc")
                  (setq #Len (+ #Len (vla-get-ArcLength x)))
                 )
                 ((vl-position (vla-get-objectname x) '("AcDbLine" "AcDbPolyline"))
                  (setq #Len (+ #Len (vla-get-Length x)))
                 )
           ) ;_ cond
         ) ;_ vlax-for
         (vla-delete #SS)
         (alert (strcat "Total Length: "
                        (setvar 'users5 (rtos #Len))
                        "\nValue can be retrieved with \"(getvar 'UserS5)\""
                ) ;_ strcat
         ) ;_ alert
        )
      ) ;_ cond
      (princ)
    ) ;_ defun

  3. #3
    Member
    Join Date
    2009-02
    Posts
    40
    Login to Give a bone
    0

    Default Re: Line Length

    Thanks Alan!

    I will give these a try on Monday.

  4. #4
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Line Length

    Quote Originally Posted by josh_j_crawford View Post
    Thanks Alan!

    I will give these a try on Monday.
    No problem.
    I updated the code to draw a vector line along the selected line instead of just between the points. Looks nicer.

  5. #5
    Active Member
    Join Date
    2015-08
    Posts
    59
    Login to Give a bone
    0

    Default Re: Line Length

    Quote Originally Posted by alanjt View Post
    No problem.
    I updated the code to draw a vector line along the selected line instead of just between the points. Looks nicer.
    Well, I can't get DBP to work at all, other fine

    Command: DBP
    Select curve:
    Specify first point on curve: end of
    Specify next point on curve: end of ; error: bad argument type: 2D/3D point: nil

  6. #6
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    1

    Default Re: Line Length

    Quote Originally Posted by steveo View Post
    Well, I can't get DBP to work at all, other fine

    Command: DBP
    Select curve:
    Specify first point on curve: end of
    Specify next point on curve: end of ; error: bad argument type: 2D/3D point: nil
    Oops, when I set it to draw a vector along the selected curve, I completely forgot to check if I could pick from end to end. It was trying to create a point beyond the curve. It should work now. Thanks for reporting that. Updated above.

  7. #7
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Line Length

    Why not try using fields? If you do this manually you can add the length of near anything to a text - as long as the line & text is in the same space (MS/PS). Then if the line/polyline/etc. is modified the text would update automatically after a regen. To get the situation of line in MS & text in PS, create a temporary field in a text in MS, copy the field-code at the bottom - then paste it into the PS text.

    To show how this could work automatically through LSP, look at the attached LSP. It's doing the Area property, but the Length would work the same way. These are set in lines 338 & 361. And probably your conversion factors would be something different than the default in the LSP (which is written for metric).
    Attached Files Attached Files

Similar Threads

  1. Type Line Length When Sketching Line
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 2
    Last Post: 2012-11-07, 04:56 AM
  2. Line length
    By Devil in forum AutoCAD General
    Replies: 5
    Last Post: 2010-06-16, 07:10 AM
  3. Zero length line
    By smooth shoes in forum AutoCAD General
    Replies: 15
    Last Post: 2007-11-12, 12:19 PM
  4. Lisp routine to list line length and line ID
    By hlecates in forum AutoLISP
    Replies: 6
    Last Post: 2007-03-21, 04:03 PM
  5. Specifying line length
    By peter.gilson in forum AutoCAD LT - General
    Replies: 2
    Last Post: 2005-06-02, 04:14 PM

Posting Permissions

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