Here's a function by James Allen.
;;; Returns all names used for a dynamic block, including
;;; the actual block name and all anonymous instances.
;;;
;;; (setq names (MWE:GetDBlockNames (list bname)))
;;;
;;; bname = Str - Dynamic block name
;;; names = List - List of all inserted blocks whose
;;; EffectiveName = bname
;;;
;;; (setq names (MWE:GetDBlockNames '("TestDBlock")))
;;; ("TestDBlock" "*U4" "*U5" "*U6")
;;;
;;; James Allen - 26Apr07
;;; Malicoat-Winslow Engineers, P.C.
;;;
;;; Thanks to Joe Burke for pointing out code 331
;;; and to Tony Tanzillo for prodding in that direction.
;;;
(defun MWE:GetDBlockNames (arglst / blk edt enm ins name names)
(mapcar 'set '(name) arglst)
(setq names (list name)
name (strcase name)
)
(vl-load-com)
(vlax-for blk (vla-get-Blocks
(vlax-get (vlax-get-Acad-Object) 'ActiveDocument))
(if
(and
(setq enm (tblobjname "block" (vla-get-Name blk)))
(setq edt (entget enm))
(= (logand (cdr (assoc 70 edt)) 1) 1)
)
(if
(and
(setq edt (entget (vlax-vla-object->ename blk)))
(setq enm (cdr (assoc 331 edt)))
(setq ins (vlax-ename->vla-object enm))
(eq (vla-get-ObjectName ins) "AcDbBlockReference")
(wcmatch (strcase (vla-get-EffectiveName ins)) name)
)
(setq names (cons (vla-get-Name blk) names))
)
)
)
(reverse names)
) ;end
Pass what the above returns to this function.
;; Argument example: ("TestDBlock" "*U4" "*U5" "*U6")
;; Returns: "TestDBlock,`*U4,`*U5,`*U6,"
(defun BlockNamesFilter (strlst)
(apply 'strcat
(mapcar
'(lambda (x)
(if (eq "*" (substr x 1 1))
(strcat "`" x ",")
(strcat x ",")
)
)
strlst
)
)
) ;end
Example:
(setq str (BlockNamesFilter strlst))
(setq ss (ssget "X" (list '(0 . "INSERT") (cons 2 str))))
Joe Burke