TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: LBC on April 22, 2004, 09:59:40 AM
-
Hi
Does any of you have a lisp that is able to calculate the total length of several plines. Please!!!!
Lars
Bordeaux, France
-
I do believe there is a routine in the new Cadlyst mag...lemme find it on their website for ya
-
Haven't tested it, but HERE (http://theswamp.org/lilly.pond/Dommy2Hotty/LL.lsp) it is.
Here's the code in it for you to look at also...
;;CADALYST 04/04 Tip1939: LL.LSP Length of Linear Objects (c) 2004 Will DeLoach
(defun c:ll (/ sset num llen)
(setq sset (ssget '((0 . "LINE,LWPOLYLINE")))
num 0
llen 0
)
(if sset
(progn
(repeat (sslength sset)
(setq llen
(+ llen
(vla-get-length (vlax-ename->vla-object (ssname sset num)))
)
)
(setq num (1+ num))
)
(setq num (rtos num 2 0)
llen (rtos llen 4)
)
(alert (strcat num " line lengths = " llen))
)
)
)
-
thanks a lot :D
I've been looking all over the web for 2 days now, whith out finding anything. I'll run a test to see if it works. :dood:
-
This will calculate total length of polylines on a specific layer. First object pick sets layer then select object needed.
(defun C:PLEN ( / layname s count len en ed count )
(setvar "CMDECHO" 0) ;0 to hide command echos
(setq layname (cdr (assoc 8
(entget (car (entsel "Select entity to define layer totaled: "))))))
(prompt "\nSelect items to total:")
(setq
S (ssget) ; Get all entities marked by user
count 0
len 0
)
(lfeed 3)
(setvar "OSMODE" 0)
(repeat (sslength S)
(setq
en (ssname S count)
ed (entget en)
count (1+ count)
)
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "POLYLINE")) (progn
(command ;Get area value
".AREA"
"E"
en
)
(setq len (+ len (getvar "perimeter")))
))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "REGION")) (progn
(command ;Get area value
".AREA"
"E"
en
)
(setq len (+ len (getvar "perimeter")))
))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "LWPOLYLINE")) (progn
(command ;Get area value
".AREA"
"E"
en
)
(setq len (+ len (getvar "perimeter")))
))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "SPLINE")) (progn
(command ;Get area value
".AREA"
"E"
en
)
(setq len (+ len (getvar "perimeter")))
))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "CIRCLE")) (progn
(command ;Get area value
".AREA"
"E"
en
)
(setq len (+ len (getvar "perimeter")))
))
); end repeat
(alert (strcat "\nThe Total Length of Selected Closed Polylines on Layer \""(princ layname)"\" is: "(rtos len (getvar "lunits") 0)))
(prompt (strcat "\n "(rtos len (getvar "lunits") 0)))
(princ)
);defun
;;;----------------------------------------------------------
;;;| LFEED |
;;;| Prints the number of line feeds passed to it. |
;;;| |
;;;----------------------------------------------------------
(defun lfeed (
count ; number of line feeds to print
)
(repeat (1- count) (princ "\n "))
(princ "\n")
(princ)
); defun
;;;*
(if debug (princ "lfeed loaded\n"))
;;;----------------------------------------------------------
;;;| DXF |
;;;| Takes an integer dxf code and an entity or entity data |
;;;| list and returns the data element of the association |
;;;| pair. |
;;;| |
;;;----------------------------------------------------------
(defun dxf (
code ; DXF code
ed ; Entity name or data list
)
; Turn entity name into entity data
(if (and (not (listp ed)) ed) (setq ed (entget ed)))
(cdr (assoc code ed)) ; Find association pair & strip 1st element
); defun
;;;*
(if debug (princ "dxf loaded\n"))
(C:plen)
-
Tested out the one I posted from Cadlyst...works just how it sounds you want it to...
-
(alert (strcat "\nThe Total Length of Selected Closed Polylines on Layer
should read (alert (strcat "\nThe Total Length of Selected Polylines on Layer...
-
If I were going to write one it might look like this:
(defun ss->vla-list (ss lst)
(cond ((ssname ss 0)
(setq lst (vl-list*
(vlax-ename->vla-object (ssname ss 0)) lst))
(ss->vla-list (ssdel (ssname ss 0) ss) lst)); 1st cond
((null (ssname ss 0)) lst); 2nd cond
); cond
)
(defun get-dist (obj)
(if (vlax-property-available-p obj 'Length)
(vlax-get-property obj 'Length)
)
)
(defun c:pline-length ( / ss vl_lst total_length)
(vl-load-com)
(gc)
(if (setq ss (ssget '((0 . "LWPOLYLINE"))))
(setq vl_lst (ss->vla-list ss nil))
)
(if vl_lst
(progn
(setq total_length (apply '+ (mapcar 'get-dist vl_lst)))
(princ
(strcat "\nTotal Length of selected Polylines = "
(rtos total_length)
)
)
)
)
(princ)
)
I wonder which one is faster ...............!!
-
Yeps it works beautifully, i only had to change the rtos value to get the metric systeme.
Thanks again
:D :D Lars