Jump to content

Measuring Individual Lengths of Multiple Lines


Recommended Posts

Hello All,

 

After trawling the help file and several other CAD forums I still haven't been able to find an easy to use solution to my prob. First post newbie and all, I'd be grateful for anyone's advice...

 

I have c.500 lines of various lengths, spaced at 10m intervals. I can select all of them and use the LIST command, escape out and use F2 to see properties of the lines, but the window only displays the properties of the last 20 or so - not the full 500.

 

I could repeat this over and over for small groups of 20 lines or so, or indeed measure and note down the length of each line individually. As everyone always is(!), I'm after a quicker way by which I could view and perhaps export the lengths of all 500 lines from LtoR as I look at them on the screen (I was planning to merely copy and paste the contents of the LS window and go from there).

 

Any help appreciated and I hope to be able to reciprocate at some point! Cheers.

Link to comment
Share on other sites

First. Welcome to the CADTutor forum CADjam.

 

Second. Now I'm going tell you to take a hike. LOL Take a hike over to the website of Cadalyst magazine that is. You'll find them at www.cadalyst.com. Look for the CAD Tips tab at the top of the first web page and click on it. At the next page use the Search feature and type in the words line length. The search will bring up several Lisp routines submitted by readers. I think the one most applicable to your situation is the routine called Entity Length. It was written by Julio Monge and submitted 01-JUL-2006. It is tip number 2127 (entlen.lsp). Two more routines that you should check out are Length and Angle by Lynn Owen and Line Length by Bill Bratt. I trust that one of the three will suit your needs.

 

You can reciprocate by reporting back on any or all that you try out and tell us what you think. Thank you.

Link to comment
Share on other sites

quick and dirty... worked the one time I tested it

(defun c:ll ()
(vl-load-com)
 (setq ss1 (ssget '((0 . "line"))); change "line" to "*line" if you want to include plines, splines
   sslen (sslength ss1)
   cnt 0)
   (if (findfile "c:\\linelengths.txt")
   (setq fn (open "c:\\linelengths.txt" "a"))
   (setq fn (open "c:\\linelengths.txt" "w"))
     )
 (repeat sslen
    (setq entname (ssname ss1 cnt)
   obj (vlax-ename->vla-object entname)
   len (rtos (vlax-get-property obj 'length) 2 4) ;adjust 4 for decimal precision
      )
 (write-line (strcat  "Line# " (rtos(1+ cnt) 2 0) (chr 9) len) fn)
 (setq cnt (1+ cnt))
   )
 (write-line (chr 10) fn)
 (close fn)
 (startapp "notepad" "c:\\linelengths.txt")
(princ)
 )

Link to comment
Share on other sites

Dang. Is the guy above the best dude you ever met or what? Where else could you go to get such good service? AutoDesk? I DON'T THINK SO! :)

Link to comment
Share on other sites

ReMark thanks for the instruction to take a hike! I got as far as the entlen LISP (which only produces a single output as the sum of all lines), before I spotted lpseifert's response. Works a treat - exactly what I'm after so thanks a plenty!! :)

Link to comment
Share on other sites

  • 7 years later...
thanks for your lisp:)

For curved lines What should I do?

By "curved lines" are you referring to arcs and splines? If so, see my response to the thread you started about the same subject.

Link to comment
Share on other sites

By "curved lines" are you referring to arcs and splines?

yes.

i run this lisp in autocad 2015 and appear this error.

"error: bad argument type: lselsetp nil

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).

Converting (command) calls to (command-s) is recommended."

Link to comment
Share on other sites

quick and dirty... worked the one time I tested it

(defun c:ll ()
(vl-load-com)
 (setq ss1 (ssget '((0 . "line"))); change "line" to "*line" if you want to include plines, splines
   sslen (sslength ss1)
   cnt 0)
   (if (findfile "c:\\linelengths.txt")
   (setq fn (open "c:\\linelengths.txt" "a"))
   (setq fn (open "c:\\linelengths.txt" "w"))
     )
 (repeat sslen
    (setq entname (ssname ss1 cnt)
   obj (vlax-ename->vla-object entname)
   len (rtos (vlax-get-property obj 'length) 2 4) ;adjust 4 for decimal precision
      )
 (write-line (strcat  "Line# " (rtos(1+ cnt) 2 0) (chr 9) len) fn)
 (setq cnt (1+ cnt))
   )
 (write-line (chr 10) fn)
 (close fn)
 (startapp "notepad" "c:\\linelengths.txt")
(princ)
 )

this lisp.this lisp run autocad 2014 correctly.

Link to comment
Share on other sites

No for windows 8.1 os.:(

I can't help you there. I'm running Windows 7. Everything works...nothing fails.

 

I do not have access to a computer running both Windows 8.1 and AutoCAD so I am unable to test lisp routines under those conditions.

Link to comment
Share on other sites

It may be something to do with "startapp". I am sure I did some stuff at home where I run Win 10 and use startapp no probs. Sorry not Win 8

 

;change to test or delete line.
; (startapp "notepad" "c:\\linelengths.txt")

Edited by BIGAL
Link to comment
Share on other sites

Another example

 

; Code by Alan H jan 2017
; make a table of objects in particular lengths
(vl-load-com)
(setvar 'ctab "Model")
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq curspace (vla-get-modelspace doc))

(defun AH:maketable ( / pt1 numrows numcolumns rowheight colwidth ) 
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table:  "))) 
; now do table 
(setq numrows 3)
(setq numcolumns 2)
(setq rowheight 0.3)
(setq colwidth 1.
(setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "Heading 1")
(vla-settext objtable 1 0 "Title 1") 
(vla-settext objtable 1 1 "Title 2")
(setq objtable (vlax-ename->vla-object (entlast)))
) ; defun

(defun AH:addlinetext ( / )
(if (= (vla-get-TextOverride obj) "") ; if text override has been done
(RTOS (vla-get-Measurement obj) 2 2)
(RTOS (vla-get-TextOverride obj) 2 2)
)
)

(defun AH:addlinet (item1 item2 / obj)
(setq rowcnt (vla-get-rows objtable))
(setq rowhgt (vla-getRowHeight objtable 2))
(vla-InsertRows objTable rowcnt rowhgt 1)
(vla-settext objtable (- rowcnt 1) 0 item1) ; rows start at 0
(vla-settext objtable (- rowcnt 1) 1 item2)
)

; do a pick exist or add here 
(defun ah:obj-table ( / objtable obj rowcnt ans)
(setq ans (getstring "New table or exist N or E"))
(if (= "N" (strcase ans))
(AH:maketable) ; make a table then 
(setq objtable (vlax-ename->vla-object (car (entsel "Pick existing table")))) ;pick existing
)

; pick multiple objects and check type
(while (/= (setq obj (vlax-ename->vla-object (car (entsel "Pick an entity")))) nil)
(setq objname (vla-get-objectname obj))
(cond
((= objname "AcDbPolyline") (AH:addlinet  "PLine length is" (rtos (vla-get-length obj) 2 2)) )
((= objname "AcDbText") (AH:addlinet "Part is" (vla-get-textstring obj)) )
((= objname "AcDbRotatedDimension")(AH:addlinet "Dim is" (AH:addlinetext)) )
((= objname "AcDbLine") (AH:addlinet  "Line length is" (rtos (vla-get-length obj) 2 2)) )
)
)

) ; AH:obj-table

(AH:obj-table)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...