Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

help with simple lisp!

3 REPLIES 3
Reply
Message 1 of 4
erik_f
153 Views, 3 Replies

help with simple lisp!

will be very greatfull for help with lisp that can calculate the total lenth of all poly lines in a specified layer!

i have just neewbee knowledge in scipting. so if someone would have the kindness to help me i will be most greatfull
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: erik_f

Made this speshul fer you.
-doug
you can change the precision if you want, and could also pick your desired layer.

(defun c:PLL ( / a b c d e total n total$) ;Polyline Layer Length
(princ "PLines on which layer?") ;add a pick-command here
(setq a (getstring T))
(setq b (ssget "X" (list (cons 0 "POLYLINE,LWPOLYLINE")(cons 8 a))))
(setq total 0.0)
(setq n 0)
(while
(setq c (ssname b n))
(command "UCS" "E" c)
(command "area" "E" c)
(setq e (getvar "perimeter"))
(setq total (+ total e))
(setq n (1+ n))
)
(setq total (rtos total 2 3)) ;change the precision here
(setq total$ (strcat "Total PLine length on layer " a " is " total))
(princ total$)
(princ)
)
"erik_f" wrote in message news:f0852bb.-1@WebX.maYIadrTaRb...
will be very greatfull for help with lisp that can calculate the total lenth of all poly lines in a specified layer!
have just neewbee knowledge in scipting. so if someone would have the kindness to help me i will be most greatfull
Message 3 of 4
Anonymous
in reply to: erik_f

This should get you started,watch the word-wrap,Thank jaysen Long for the MASSOC routine

hope it helps
-J-
"And know on to scene 24...."
------------------------------------------------
;;polycount by Jonathan Trostad
;;finds polys on a layer, & gets their endpoints

(defun c:polycount (/ POLYENT MULTI TOTLNGTH RTOTLNGTH SSPART CNT CNT1 LIMIT ptlngt EPTS)
(setq POLYENT (car (entsel "\nSelect Polyline")))
(initget "Yes No")
(setq MULTI (getkword "\nAll Polylines on this layer? [Yes/No] :"))
(setq TOTLNGTH 0
RTOTLNGTH 0)
(if (equal "Yes" MULTI)
(progn
(setq POLYENT (entget POLYENT))
(setq SSPART (list'(0 . "POLYLINE,LWPOLYLINE")(assoc 8 POLYENT)));;find layer
(setq SSPART (ssget "x" SSPART));;find all polys on layer
(setq cnt 0)
(setq LIMIT (sslength SSPART));;how many polys?
(repeat LIMIT
(setq POLYENT (ssname SSPART cnt))
(setq EPTS (massoc 10 (entget POLYENT)));;get endpts
(setq ptlngt (1- (length EPTS))
cnt1 0)

(while
(> ptlngt (+ cnt1 1))
(setq POLYLNGTH (distance (nth cnt1 EPTS) (nth (+ cnt1 1)EPTS));;find segment dist
TOTLNGTH (+ TOTLNGTH POLYLNGTH);; add to total distance
cnt1 (+ cnt1 1))
);end while
(setq RTOTLNGTH (+ RTOTLNGTH TOTLNGTH))
(setq cnt (1+ cnt))
);end limit
);end progn
(progn
(setq EPTS (massoc 10 (entget POLYENT)));;get endpts
(setq ptlngt (1- (length EPTS))
cnt1 0)

(while
(> ptlngt (+ cnt1 1))
(setq POLYLNGTH (distance (nth cnt1 EPTS) (nth (+ cnt1 1)EPTS));;find segment dist
RTOTLNGTH (+ RTOTLNGTH POLYLNGTH);; add to total distance
cnt1 (+ cnt1 1))
);end while
);end else progn

);end if

(princ RTOTLNGTH)
(princ)
);end defun
-------------------------------------------
;Example: (massoc 10 (entget (car (entsel "\nSelect a polyline: "))))
;by Jaysen Long

(defun massoc (key alist / x nlist)
(foreach x alist
(if
(eq key (car x))
(setq nlist (cons (cdr x) nlist))
);end if
);end foreach
(reverse nlist)
);end defun
Message 4 of 4
erik_f
in reply to: erik_f

GREAT! GREAT! GREAT!
I am so impressed just excatly what i hoped for.

My best regards to you, i also thanks jtrostad for helping.(i tried Dougs first and it did it!)

/happy Erik

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost