AutoCAD automation has been discussed several times in this blog. Various add-ins and VBA codes have been presented, mainly for drawing polylines and measuring lines’ length.Below you will find another useful VBA add-in that automatically lists all the blocks that exist in the active drawing. The add-in is in reality a form, containing a list box control, a text box and three buttons. In the SelectSimilar Settings box, I choose only the Name field and click OK. Next, I select one of the SMOKE blocks, and press Enter. In the Properties box, you will see “Block Reference (38)” at the top. The (38) represents the number of times the block is found in that drawing, and hence your device count.
block count lisp
block count lisp
The below lisp gives me an error. Can anyone help me out?
;Tip1752: LIST_ELEM.LSP List blocks (C)2001, Andrzej Gumula
; *********** Modified to just 'list' to 'drawingname'.txt file.
; Modified by: Bob Shaw (ECCAD)
; Lisp for make list of Blocks or Shape in selected ASCII file
(defun ADD (A B / C)
(while (/= A (car C))
(setq C (car B)
B (cdr B)
)
) ;end while
(cdr C)
) ;end add
(defun C:LIST_ELEM (/ CM RYS WHAT ZBIOR TEMP NAME ITEM LISTA FILE)
(setq CM (getvar 'cmdecho')
RYS (getvar 'dwgname')
LISTA NIL
)
(setvar 'cmdecho' 0)
(initget 'Insert Shape')
(setq WHAT (cond ((getkword 'nShapes,<Insert blocks>: '))
(t 'INSERT')
)
)
(cond ((setq ZBIOR (ssget (list (cons 0 (strcase WHAT)))))
(repeat (setq TEMP (sslength ZBIOR))
(setq TEMP (1- TEMP)
NAME (cdr (assoc 2 (entget (ssname ZBIOR TEMP))))
)
(cond ((not (member NAME (mapcar 'car LISTA)))
(setq LISTA (append LISTA (list (cons NAME 1))))
)
(t
(setq ITEM (ADD NAME LISTA)
LISTA (subst (cons NAME (1+ ITEM)) (cons NAME ITEM) LISTA)
)
)
) ;end cond
) ;end repeat
; Old code here
; (cond ((setq NAME (getfiled 'FILE WITH LIST OF ELEMENTS'
; (substr RYS 1 (- (strlen RYS) 4))
; 'txt'
; 1
; )
; )
; (setq FILE (open NAME 'w'))
; (foreach X LISTA
; (write-line (strcat (car X) ' ' (itoa (cdr X))) FILE)
; )
; (setq FILE (close FILE))
; )
; (t (prompt 'nNo file selected. '))
; )
; )
; (t (prompt 'nNothing selected. '))
; ) ;end cond
; New code here
(setq NAME (strcat (substr RYS 1 (- (strlen RYS) 4)) '.txt'))
(setq FILE (open NAME 'w'))
(foreach X LISTA
(write-line (strcat (car X) ' ' (itoa (cdr X))) FILE)
); foreach
(setq FILE (close FILE))
;; end of new code
(setvar 'cmdecho' CM)
(princ)
) ;end file
(prompt 'nLoaded new command LIST_ELEM. ')
(princ)
;Tip1752: LIST_ELEM.LSP List blocks (C)2001, Andrzej Gumula
; *********** Modified to just 'list' to 'drawingname'.txt file.
; Modified by: Bob Shaw (ECCAD)
; Lisp for make list of Blocks or Shape in selected ASCII file
(defun ADD (A B / C)
(while (/= A (car C))
(setq C (car B)
B (cdr B)
)
) ;end while
(cdr C)
) ;end add
(defun C:LIST_ELEM (/ CM RYS WHAT ZBIOR TEMP NAME ITEM LISTA FILE)
(setq CM (getvar 'cmdecho')
RYS (getvar 'dwgname')
LISTA NIL
)
(setvar 'cmdecho' 0)
(initget 'Insert Shape')
(setq WHAT (cond ((getkword 'nShapes,<Insert blocks>: '))
(t 'INSERT')
)
)
(cond ((setq ZBIOR (ssget (list (cons 0 (strcase WHAT)))))
(repeat (setq TEMP (sslength ZBIOR))
(setq TEMP (1- TEMP)
NAME (cdr (assoc 2 (entget (ssname ZBIOR TEMP))))
)
(cond ((not (member NAME (mapcar 'car LISTA)))
(setq LISTA (append LISTA (list (cons NAME 1))))
)
(t
(setq ITEM (ADD NAME LISTA)
LISTA (subst (cons NAME (1+ ITEM)) (cons NAME ITEM) LISTA)
)
)
) ;end cond
) ;end repeat
; Old code here
; (cond ((setq NAME (getfiled 'FILE WITH LIST OF ELEMENTS'
; (substr RYS 1 (- (strlen RYS) 4))
; 'txt'
; 1
; )
; )
; (setq FILE (open NAME 'w'))
; (foreach X LISTA
; (write-line (strcat (car X) ' ' (itoa (cdr X))) FILE)
; )
; (setq FILE (close FILE))
; )
; (t (prompt 'nNo file selected. '))
; )
; )
; (t (prompt 'nNothing selected. '))
; ) ;end cond
; New code here
(setq NAME (strcat (substr RYS 1 (- (strlen RYS) 4)) '.txt'))
(setq FILE (open NAME 'w'))
(foreach X LISTA
(write-line (strcat (car X) ' ' (itoa (cdr X))) FILE)
); foreach
(setq FILE (close FILE))
;; end of new code
(setvar 'cmdecho' CM)
(princ)
) ;end file
(prompt 'nLoaded new command LIST_ELEM. ')
(princ)
how to count the items in the drawings
how to count the items in the drawings
I'm a formwork designer. I'm drawing a thound of formwork shop drawings and have to count how many items, such as couplings,panels, nuts,bolts...etc, are used in the drawing.
I just count them one by one after finishing the shop drawing. it's not difficult because every item is same size( same bolt size, same coupling size.....) if it is not complicated)
Is there any method or good command that AutoCAD does the job for me if I want the number of special item such as bolt in the plans?
I just count them one by one after finishing the shop drawing. it's not difficult because every item is same size( same bolt size, same coupling size.....) if it is not complicated)
Is there any method or good command that AutoCAD does the job for me if I want the number of special item such as bolt in the plans?