See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to get length of line

  1. #1
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Angry How to get length of line

    I have a somaby lines. I want to measure it individual and sum it and give me final length of conductor by selecting all the lines.


    it gives me property like:

    ((-1 . <Entity name: 78ee2870>) (0 . "LWPOLYLINE") (330 . <Entity name:
    7d888c10>) (5 . "2BF9E") (100 . "AcDbEntity") (67 . 0) (410 . "MODEL") (8 .
    "GRID") (100 . "AcDbPolyline") (90 . 2) (70 . 0) (43 . 0.0) (38 . 0.0) (39 .
    0.0) (10 455452.0 336457.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 455452.0
    221507.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))

    first point is: (10 455452.0 336457.0)
    second point is: 10 455452.0 221507.0)

    How can I call this different type of point bus assoc description is same (10)

    or some thing else can be done.


    Avinash Patil
    Pixle park

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: How to get length of line

    Quote Originally Posted by avinash00002002
    I have a somaby lines. I want to measure it individual and sum it and give me final length of conductor by selecting all the lines.


    it gives me property like:

    ((-1 . <Entity name: 78ee2870>) (0 . "LWPOLYLINE") (330 . <Entity name:
    7d888c10>) (5 . "2BF9E") (100 . "AcDbEntity") (67 . 0) (410 . "MODEL") (8 .
    "GRID") (100 . "AcDbPolyline") (90 . 2) (70 . 0) (43 . 0.0) (38 . 0.0) (39 .
    0.0) (10 455452.0 336457.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 455452.0
    221507.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))

    first point is: (10 455452.0 336457.0)
    second point is: 10 455452.0 221507.0)

    How can I call this different type of point bus assoc description is same (10)

    or some thing else can be done.
    That is an LWPOLYLINE entity, not a line. Look at DXF group code 0

    Pass your entity to this function to retreive the length

    Code:
    (defun getlen (ent)
    (vla-get-length (vlax-ename->vla-object ent))
    )
    R.K. McSwain | CAD Panacea |

  3. #3
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: How to get length of line

    Please note I have *moved* this thread from the VBA Forum to this one due to the AutoLisp property information listed and the AutoLisp solution provided.

    Thanks,

    Richard
    Forum Moderator
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: How to get length of line

    Sorry, I forgot. Here is a complete solution.

    Load this, run GETLENS at the command prompt, length will be returned in an ALERT dialog.

    Code:
    (defun getlen (ent)
      (vla-get-length (vlax-ename->vla-object ent))
    )
    (defun c:getlens ()
      (setq sset (ssget "X" '((0 . "LWPOLYLINE"))) tot 0.0 i 0)
      (repeat (sslength sset)
    	(setq tot (+ tot (getlen (ssname sset i))) i (1+ i))
      )
      (alert (strcat "Total Length = " (rtos tot)))
    )
    R.K. McSwain | CAD Panacea |

  5. #5
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: How to get length of line

    Use this to see length as you pick each.

    Code:
    ;;  CAB  05/04/2005
    ;;  Total length print
    (defun c:tlength (/ en len lentotal typ)
      (vl-load-com)
      (setq lentotal 0)
      (while (setq en (entsel "\nPick object for length."))
        (setq en (car en))
        (if (member (setq typ (cdr (assoc 0 (entget en))))
                    '("LWPOLYLINE" "POLYLINE" "LINE" "SPLINE" "ARC")
            )
          (progn
            (setq len      (vlax-curve-getdistatparam en (vlax-curve-getendparam en))
                  lentotal (+ len lentotal)
            )
            (prompt (strcat "\nLength of " typ " is " (rtos len)))
            (prompt (strcat "\n***  Running Total is " (rtos lentotal) "  ***"))
          )
          (prompt "\n***  Wrong type object, try again.")
        )
      )
      (if lentotal
        (prompt (strcat "\n***  Grand Total length is " (rtos lentotal) "  ***"))
      )
      (princ)
    )
    (prompt "\nLength Total loaded, Enter tlength to run")
    (princ)

  6. #6
    I could stop if I wanted to
    Join Date
    2003-11
    Posts
    277
    Login to Give a bone
    0

    Default Re: How to get length of line

    Quote Originally Posted by avinash00002002
    I have a somaby lines. I want to measure it individual and sum it and give me final length of conductor by selecting all the lines.


    it gives me property like:

    ((-1 . <Entity name: 78ee2870>) (0 . "LWPOLYLINE") (330 . <Entity name:
    7d888c10>) (5 . "2BF9E") (100 . "AcDbEntity") (67 . 0) (410 . "MODEL") (8 .
    "GRID") (100 . "AcDbPolyline") (90 . 2) (70 . 0) (43 . 0.0) (38 . 0.0) (39 .
    0.0) (10 455452.0 336457.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 455452.0
    221507.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))

    first point is: (10 455452.0 336457.0)
    second point is: 10 455452.0 221507.0)

    How can I call this different type of point bus assoc description is same (10)

    or some thing else can be done.


    Avinash Patil
    Pixle park
    Hi Avinash Patil,
    Here more simple
    Code:
    (setq ss (car (entsel "\nSelect a object")))
    (setq tlen (vla-get-length (vlax-ename->vla-object ss)))

  7. #7
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: How to get length of line

    Quote Originally Posted by Adesu
    Hi Avinash Patil,
    Here more simple
    Code:
    (setq ss (car (entsel "\nSelect a object")))
    (setq tlen (vla-get-length (vlax-ename->vla-object ss)))
    ...about the same as http://forums.augi.com/showthread.ph...729#post344729
    R.K. McSwain | CAD Panacea |

  8. #8
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: How to get length of line

    use this code to get the length of a line or any other curve entity

    Code:
    ;Test the curve_length function
    ;enter test_curve_lingth at command line
    (defun c:test_Curve_length()
    (curve_length(car (entsel)))
     
    )
    ;function curve_length(en)
    ;return length of the curve
    ; en is the entitiy name of a curve entity
    ;2dPolyline
    ;3dPolyline
    ;Arc
    ;Circle
    ;Ellipse
    ;Leader
    ;Line
    ;Polyline
    ;Ray
    ;Spline
    
    (defun curve_length(en)
    (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en))
    )
    edit code 05/23/06 line function name type wrong
    Last edited by jwanstaett; 2006-05-23 at 01:03 PM.

  9. #9
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: How to get length of line

    Quote Originally Posted by jwanstaett
    use this code to get the length of a line or any other curve entity. . .
    Sorry, it will not work on a Ray, and you must convert "en" to "Vl-Obj"

    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2006-05-23 at 11:30 AM.

  10. #10
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    1

    Default Re: How to get length of line

    Try this :
    Code:
    (defun c:Length ( / Ent Vl-Obj ObjLen )
      (setq Ent (entsel) )
      (if (and Ent (member (cdr (assoc 0 (entget (car Ent )))) (list "LINE" "ARC" "CIRCLE" "LWPOLYLINE" "POLYLINE" "LEADER" "SPLINE" "ELLIPSE" )) )
        (progn
          (vl-load-com)
          (setq Vl-Obj (vlax-ename->vla-object (car Ent )) )
          (princ (strcat "\nCommand: " (cdr (assoc 0 (entget (car Ent )))) " length is : " (rtos (vlax-curve-getDistAtParam Vl-Obj (vlax-curve-getEndParam Vl-Obj )))) )
        )
        (if Ent (princ "Not a legal object. " ) (princ "..nothing Selected." ) )
      )
      (princ)
    )
    : ) Happy Computing !

    kennet

    PS. If you use any Code I post or Down Load Attachment I would like to say. . . Thank You, and enjoy.

Page 1 of 2 12 LastLast

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
  •