Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting blocks

Status
Not open for further replies.

shadow

Computer
Mar 1, 2001
321
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 &quot;\nType block name or <enter> to pick: &quot;))
(if (= blkname &quot;&quot;)
(setq blkname (cdr (assoc 2 (entget (car (entsel))))))
)
(setq blockset (ssget &quot;X&quot; (list (cons 2 blkname))))
(setq total (sslength blockset))
(if (= total 1)
(progn
(princ &quot;\n &quot;)(princ &quot;\n &quot;)(princ &quot;\n &quot;)(princ &quot;\n &quot;)
(textscr)
(princ &quot;\nThere is &quot;)(princ total)(princ &quot; block called &quot;)(princ blkname)(princ&quot;....&quot;)
(princ &quot;\n &quot;)(princ &quot;\n &quot;)
)
)
(if (> total 1)
(progn
(princ &quot;\n &quot;)(princ &quot;\n &quot;)
(princ &quot;\n &quot;)(princ &quot;\n &quot;)
(textscr)
(princ &quot;\nThere are &quot;)(princ total)(princ &quot; blocks called &quot;)(princ blkname)(princ&quot;....&quot;)
(princ &quot;\n &quot;)(princ &quot;\n &quot;)
)
)
(setvar &quot;cmdecho&quot; 1)
(princ)
)
if everyone helps everybody the world will be a better place
 
Replies continue below

Recommended for you

Try this edited code...

(defun c:cntblks ()
(setvar &quot;cmdecho&quot; 0)
(setq blkname (getstring &quot;\nType block name or <enter> to pick: &quot;))
(if (= blkname &quot;&quot;)
(setq blkname (cdr (assoc 2 (entget (car (entsel))))))
)
;;; ADDED CODE HERE
(setq layname (cdr (assoc 2 (tblnext &quot;layer&quot; t))))
(textscr)
(princ &quot;\nBLOCK\tLAYER\tQUANITY&quot;)
(while layname
(setq blockset (ssget &quot;X&quot; (list (cons 2 blkname)(cons 8 layname))))
(if blockset
(setq total (sslength blockset))
(setq total 0)
)
;;; END ADDED CODE
; (setq blockset (ssget &quot;X&quot; (list (cons 2 blkname))))
; (setq total (sslength blockset))
; (if (= total 1)
; (progn
; (princ &quot;\n &quot;)(princ &quot;\n &quot;)(princ &quot;\n &quot;)(princ &quot;\n &quot;)
; (textscr)
; (princ &quot;\nThere is &quot;)(princ total)(princ &quot; block called &quot;)(princ blkname)(princ&quot;....&quot;)
; (princ &quot;\n &quot;)(princ &quot;\n &quot;)
; )
; )
; (if (> total 1)
; (progn
;;; ADDED CODE HERE
(if (> total 0)
(progn
(princ &quot;\n&quot;)
(princ blkname)
(princ &quot;\t&quot;)
(princ layname)
(princ &quot;\t&quot;)
(princ total)
;;; END ADDED CODE
; (princ &quot;\n &quot;)(princ &quot;\n &quot;)
; (princ &quot;\n &quot;)(princ &quot;\n &quot;)
; (textscr)
; (princ &quot;\nThere are &quot;)(princ total)(princ &quot; blocks called &quot;)(princ blkname)(princ&quot;....&quot;)
; (princ &quot;\n &quot;)(princ &quot;\n &quot;)
)
)
;;; ADDD CODE HERE
(setq layname (cdr (assoc 2 (tblnext &quot;layer&quot;))))
)
;;; END ADDED CODE
(setvar &quot;cmdecho&quot; 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.
 
ok that kinda worked but its still to where you either have to know the blocks name or be able to select the block how can i make it so that i just window in an area and any blocks with in that window are listed

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
 
Forward your email address to lisper@bcinc.hypermart.net and I will send you something that should do the trick
 
See below:

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 &quot;X&quot; from ssget statement and

it will do this for a selected area.

Hope this is useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor