TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Slim© on May 26, 2004, 04:15:13 PM
-
I've been looking and looking, etc., but as of yet haven't figured out how to get the length of a polyline in lisp.
How would I go about doing this?
I know it can be done, as when you list a polyline, you get a length.
Please help.
Thanks.
-
Ill give you a hint:
"Explode"
-
Like this......
(defun getlength (ent / objPoly len)
(if (wcmatch (strcase (cdr (assoc 0 (entget (car ent))))) "*LINE,ARC")
(setq objPoly (vlax-ename->vla-object (car ent))
len (vlax-curve-getdistAtParam objPoly
(vlax-curve-getEndParam objPoly))
)
)
)
(defun c:length ( / ent)
(if (setq ent (entsel "\nSelect object to obtain length for: "))
(if (setq len (getlength ent))
(princ (strcat "\nObject length is: " (rtos len)))
(princ "\nObject doesn't have a length.")
)
(princ "\nNothing selected, exiting...")
)
(princ)
)
Jeff
-
Se7en Thanks for that, we'll see where we go from there.
-
or like that ^. LoL
-
Ya sure, that's the ticket. :D
-
Well, I forgot which board I was viewing and didn't realize that I was just a Guest when I posted that solution. Now I'm all logged in and official and will state for the record that the masked Guest above was, in fact, I. :lol:
Jeff
-
Thank You much, Jeff :D
-
Here's one that reports all plines on a specific layer (inspired from a discussion (http://www.cadtutorforum.net/forum/viewtopic.php?t=1439) on the CADTutor forum):
(defun c:PLLEN (/ a ar cl cn i l la le obj ss)
(cond ((setq ss (entsel "\nPick any object on the required layer: "))
(setq la (cdr (assoc 8 (entget (car ss)))))
(mapcar 'set '(ar le cn i)'((0 0)(0 0) 0 0))
(cond ((setq ss (ssget "X" (list '(0 . "*POLYLINE") (cons 8 la)
'(-4 . "<") '(70 . 8)))
)
(repeat (sslength ss)
(setq obj (vlax-ename->vla-object (ssname ss i))
a (vlax-curve-getArea obj)
l (vlax-curve-getDistAtParam obj
(vlax-curve-getEndParam obj))
cl (vlax-curve-isClosed obj)
ar (mapcar '+ ar (if cl (list a 0)(list 0 a)))
le (mapcar '+ le (if cl (list l 0)(list 0 l)))
cn (+ cn (if cl 1 0))
i (1+ i)
)
)
(mapcar 'princ (list "\nTotal length: " (apply '+ le) " (closed: " (car le)
")\nTotal area: " (apply '+ ar) " (closed: " (car ar)
")\n" (sslength ss) " plines on layer " la " (closed: " cn ")")
)
)
((princ "\nNone found"))
)
)
)
(princ)
)
-
Very Nice I like it. THX :D
-
Great. You're welcome