This is currently working, I'm just looking for suggestions for improvments?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Routine: GetBlockInserts ;;;
;;; Purpose: Get a list of all insertions of specified blocks. ;;;
;;; Arguments: doc - vla-document object (or objectdbx document). If nil, then;;;
;;; the active document is used. ;;;
;;; bnames - a list of strings, the block names for the subject ;;;
;;; blocks. ;;;
;;; ReturnEnames - boolean, non-nil returns entity names, nil ;;;
;;; returns vla-objects. ;;;
;;; Returns: A list of all the insertions of the subject blocks. -1 if the ;;;
;;; block is not defined. Nil if the block is defined but has no ;;;
;;; insertions, thus: ;;;
;;;-----------------------------------------------------------------------------;;;
;;;(("tes1" ;insertions of tes1 ;;;
;;; #<VLA-OBJECT IAcadBlockReference 0f306ad4> ;;;
;;; #<VLA-OBJECT IAcadBlockReference 242f08e4> ;;;
;;; #<VLA-OBJECT IAcadBlockReference 242ede74> ;;;
;;; #<VLA-OBJECT IAcadBlockReference 242f0724> ;;;
;;; #<VLA-OBJECT IAcadBlockReference 242edee4> ;;;
;;; #<VLA-OBJECT IAcadBlockReference 242efb54> ;;;
;;; ) ;;;
;;; ("tes2") ;there are no insertions of tes2;;;
;;; ("tes3" . -1) ;tes3 doesn't exist ;;;
;;; ("LOGO" #<VLA-OBJECT IAcadExternalReference 0e83b194>);insertions of logo ;;;
;;; ("BRD_TTL" #<VLA-OBJECT IAcadBlockReference 242edb64>);insertions of brd_ttl;;
;;;) ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetBlockInserts(doc bnames ReturnEnames / objBlockDef InsList Blocks)
(setq
doc (if doc doc (vla-get-activedocument(vlax-get-acad-object)))
blocks (vla-get-blocks doc)
)
(mapcar
(function
(lambda(bname)
(setq inslist nil)
(cons bname
(cond
;;the block doesn't exist
((vl-catch-all-error-p
(setq objBlockDef (vl-catch-all-apply 'vla-item (list blocks bname)))
)
-1
)
(T
(setq
InsList (vl-remove-if-not
(function
(lambda(x)
(and
(= 331 (car x))
(entget (cdr x))
)
)
)
(member '(102 . "{BLKREFS") (entget (vlax-vla-object->ename objBlockDef)))
)
inslist (if ReturnEnames
(mapcar
(function
(lambda(x)
(cdr x)
)
)
inslist
)
(mapcar
(function
(lambda(x)
(vlax-ename->vla-object (cdr x))
)
)
inslist
)
)
)
)
)
)
)
)
bnames
)
)