Hi please someone tell me how can i get the inserted block names in a drawing?
(defun c:blkname () (setq obj (car (entsel "\nPick Block..."))) (setq bname (cdr (assoc 2 (entget obj)))) ) That will allow the user to pick a block to return a name (defun c:allblocks () (setq objgroup (ssget "x" '((0 . "INSERT")))) (setq count 0) (repeat (sslength objgroup) (setq obj (ssname objgroup count)) (setq bname (cdr (assoc 2 (entget obj)))) <Here is where you do whatever you what to do to each block> (setq count (+ 1 count)) );end while );end defun note: this will also select xrefs, if you don't want them there is a group code you can use to filter them out but I don't remember what it is...
thanks but this routines count all blocks maybe we have several copy of a block you now I just need the used block name in a drawing
expanding the code from kendresen you can do the following: (defun c:allusedblocks () (setq objgroup (ssget "x" '((0 . "INSERT")))) (setq count 0 bllist nil) (repeat (sslength objgroup) (setq obj (ssname objgroup count)) (setq bname (cdr (assoc 2 (entget obj)))) (if (not (member bname bllist)) (setq bllist (cons bname bllist)) ) (setq count (+ 1 count)) );end while bllist );end defun bob.at
(this will list all blocks defined in the drawing, whether they are used or not. (defun blkList (/ data name tmp rtn) (while (setq data (tblnext "block" (null data))) (setq name (cdr (assoc 2 data))) (if (not (= 4 (logand 4 (cdr (assoc 70 data))))) (setq rtn (cons name rtn)) ) ) (reverse rtn) )