
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi helpers, Need a small modification in lisp
Dear Helpers,
I have a lisp code that can count blocks in different layer. I need a modification like it can give blocks quantities in selected closed polylines which are in different layers.
I have two lisp codes now. Can anyone please help me to recode them.
Lisp code 1: (LIST THE TOTAL BLOCK COUNT WITH NAMES IN SELECTED AREA)
(defun C:BLKLST (/ BLKS CHK I J K L L1 N BNAME ENAME EDATA BLIST BNUM
BNAME1 BNAME2 TEMP1 TEMP2
)
(princ "\nUse standard selection methods to ")
(setq BLKS (ssget (list (cons 0 "INSERT"))))
(setq L (sslength BLKS))
(setq L (- L 1))
(setq I 0)
(setq BLIST (list "BLOCK NAMES"))
(setq BNUM (list "INSTANCES"))
(while (<= I L)
(setq ENAME (ssname BLKS I))
(setq EDATA (entget ENAME))
(setq BNAME (assoc 2 EDATA))
(setq BNAME (cdr BNAME))
(setq CHK (member BNAME BLIST))
(if (eq CHK NIL)
(setq BLIST (cons BNAME BLIST))
) ;_ end of if
(setq I (+ I 1))
) ; end while
(setq L1 (length BLIST))
(setq L1 (- L1 2))
(setq J 0)
(setq N 0)
(setq K 0)
(while (<= K L1)
(setq N 0)
(setq BNAME1 (nth K BLIST))
(setq J 0)
(while (<= J L)
(setq ENAME (ssname BLKS J))
(setq EDATA (entget ENAME))
(setq BNAME2 (assoc 2 EDATA))
(setq BNAME2 (cdr BNAME2))
(if (eq BNAME1 BNAME2)
(setq N (+ N 1))
) ;_ end of if
(setq J (+ J 1))
) ; end while j
(setq BNUM (cons N BNUM))
(setq K (+ K 1))
) ; end while k
;;; Formatting
(setq K 0)
(princ)
(command "TEXTSCR")
(princ "\nBlock Name Instance")
(while (<= K L1)
(setq TEMP1 (nth K BLIST))
(setq TEMP2 (nth (- L1 K) BNUM))
(princ "\n")
(princ TEMP1)
(princ "\t\t\t")
(princ TEMP2)
(setq K (+ K 1))
) ; end while k
(princ "\n\nPress the <F2> key to hide the text screen after viewing results... ")
(princ)
) ;_ end of defun
;(princ
; "\n Blocklst loaded... Start command by typing BLOCKLST "
;(princ)
Lisp code 2: (COUNT SELECTED BLOCKS LAYER WISE)
(defun c:LBC (/ en ss ctr bl the_list n)
(setq ss (ssget (list (cons 0 "INSERT")))
ctr (sslength ss)
)
(repeat ctr
(setq ctr (1- ctr)
en (entget (ssname ss ctr))
bl (strcat (cdr (assoc 2 en))"/"(cdr (assoc 8 en)))
)
(if (setq count (cdr (assoc bl the_list)))
(setq the_list (subst (cons bl (1+ count))(cons bl count) the_list))
(setq the_list (cons (cons bl 1) the_list))
)
)
(setq the_list (vl-sort the_list '(lambda (e1 e2)(< (car e1) (car e2)))))
(foreach n the_list
(princ (strcat "\nBlock/Layer: " (car n) ", count of :" (itoa (cdr n))))
)
)
Thanks,
T.Brahmanandam
Solved! Go to Solution.