Counting blocks
Counting blocks
(OP)
ok well i have found 2 or 3 lisps that do this but dont exactly work the way i want them to i will post the one that i have now that actually counts for me now but what im looking for is one that gives me name of block then the layer that its on how many are on that layer and then if there are more on another layer list that layer and how many that is on it and continues on to the next one
the lisp i have now currently you give the block name it returns the entire drawing amount but nothing else or you can pick a block it will tell you the nam and how many there are in the drawing but like i said im looking for more something that i can just window in an area and it tell me the following
Block Name Layer Amount
if anyone wants it this is the block count routine i have
(defun c:cntblks ()
(setvar "cmdecho" 0)
(setq blkname (getstring "\nType block name or <enter> to pick: "))
(if (= blkname "")
(setq blkname (cdr (assoc 2 (entget (car (entsel))))))
)
(setq blockset (ssget "X" (list (cons 2 blkname))))
(setq total (sslength blockset))
(if (= total 1)
(progn
(princ "\n ")(princ "\n ")(princ "\n ")(princ "\n ")
(textscr)
(princ "\nThere is ")(princ total)(princ " block called ")(princ blkname)(princ"....")
(princ "\n ")(princ "\n ")
)
)
(if (> total 1)
(progn
(princ "\n ")(princ "\n ")
(princ "\n ")(princ "\n ")
(textscr)
(princ "\nThere are ")(princ total)(princ " blocks called ")(princ blkname)(princ"....")
(princ "\n ")(princ "\n ")
)
)
(setvar "cmdecho" 1)
(princ)
)
the lisp i have now currently you give the block name it returns the entire drawing amount but nothing else or you can pick a block it will tell you the nam and how many there are in the drawing but like i said im looking for more something that i can just window in an area and it tell me the following
Block Name Layer Amount
if anyone wants it this is the block count routine i have
(defun c:cntblks ()
(setvar "cmdecho" 0)
(setq blkname (getstring "\nType block name or <enter> to pick: "))
(if (= blkname "")
(setq blkname (cdr (assoc 2 (entget (car (entsel))))))
)
(setq blockset (ssget "X" (list (cons 2 blkname))))
(setq total (sslength blockset))
(if (= total 1)
(progn
(princ "\n ")(princ "\n ")(princ "\n ")(princ "\n ")
(textscr)
(princ "\nThere is ")(princ total)(princ " block called ")(princ blkname)(princ"....")
(princ "\n ")(princ "\n ")
)
)
(if (> total 1)
(progn
(princ "\n ")(princ "\n ")
(princ "\n ")(princ "\n ")
(textscr)
(princ "\nThere are ")(princ total)(princ " blocks called ")(princ blkname)(princ"....")
(princ "\n ")(princ "\n ")
)
)
(setvar "cmdecho" 1)
(princ)
)
if everyone helps everybody the world will be a better place





RE: Counting blocks
(defun c:cntblks ()
(setvar "cmdecho" 0)
(setq blkname (getstring "\nType block name or <enter> to pick: "))
(if (= blkname "")
(setq blkname (cdr (assoc 2 (entget (car (entsel))))))
)
;;; ADDED CODE HERE
(setq layname (cdr (assoc 2 (tblnext "layer" t))))
(textscr)
(princ "\nBLOCK\tLAYER\tQUANITY")
(while layname
(setq blockset (ssget "X" (list (cons 2 blkname)(cons 8 layname))))
(if blockset
(setq total (sslength blockset))
(setq total 0)
)
;;; END ADDED CODE
; (setq blockset (ssget "X" (list (cons 2 blkname))))
; (setq total (sslength blockset))
; (if (= total 1)
; (progn
; (princ "\n ")(princ "\n ")(princ "\n ")(princ "\n ")
; (textscr)
; (princ "\nThere is ")(princ total)(princ " block called ")(princ blkname)(princ"....")
; (princ "\n ")(princ "\n ")
; )
; )
; (if (> total 1)
; (progn
;;; ADDED CODE HERE
(if (> total 0)
(progn
(princ "\n")
(princ blkname)
(princ "\t")
(princ layname)
(princ "\t")
(princ total)
;;; END ADDED CODE
; (princ "\n ")(princ "\n ")
; (princ "\n ")(princ "\n ")
; (textscr)
; (princ "\nThere are ")(princ total)(princ " blocks called ")(princ blkname)(princ"....")
; (princ "\n ")(princ "\n ")
)
)
;;; ADDD CODE HERE
(setq layname (cdr (assoc 2 (tblnext "layer"))))
)
;;; END ADDED CODE
(setvar "cmdecho" 1)
(princ)
)
You can remove all of the commented lines to make the file smaller, I left them in so you could see the changes easily.
RE: Counting blocks
also the columns ae not lining up where do i edit the routine to add space between columns
if everyone helps everybody the world will be a better place
RE: Counting blocks
RE: Counting blocks
Autolisp to filter Blocks by rotation
The lisp routine I provided there:
-counts the blocks,
-gives their rotations in radians
For the whole drawing.
Remove the "X" from ssget statement and
it will do this for a selected area.
Hope this is useful.