@ Lee:
What do you think of this version? (I had to write it in this form for compatibility with the previous...)
; Function: ALE_Block_GetInserts
;
; Version 1.00 - 30/11/2005
; Version 1.01 - 06/12/2005
; Version 2.03 - 22/02/2015
;
; Description:
; returns a list of all blocks in VlaDoc matching Layout names,
; Layers names and Block names
;
; Arguments:
; LayNms: Layout names - Wcmatch string > "Model,Layout1" or "*" for all
; LyrNms: Layer names - Wcmatch string > "Layer1,Layer2*" or "*" for all
; BlkNms: Block names - Wcmatch string > "Block001,BlockNnn" or "*" for all
; > "[~*]*" > no anonimous blocks
; FlgAtt
; = :vlax-true > only with attribs
; = :vlax-false > only without attribs
; = nil > all
;
; Return Values: LIST
;
; Example:
; (ALE_Block_GetInserts
; (vla-get-activedocument (vlax-get-acad-object)) "*" "*" "*" nil
; )
;
; Block name Layer name Layout name
; > (("TITLEBLOCK" "LAYERX" "MODEL"
; #<VLA-OBJECT IAcadBlockReference2 08330c34>) (...) ...)
;
(defun ALE_Block_GetInserts (VlaDoc LayNms LyrNms BlkNms FlgAtt / VlaObj LayNam LyrNam BlkNam OutLst Ss_Tmp Countr EntNam)
(cond
( (not (= 'VLA-OBJECT (type VlaDoc))) )
( (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-ActiveLayer (list VlaDoc)))
; ActiveLayer it is not a property of a IAxDbDocument: Interface then
; I use vla-get-layouts else (ssget "_X" ...) because it is 20 times faster
;(vlax-property-available-p VlaDoc 'Layouts) ;da aggiungere in futuro 20140213
(vlax-for LayFor (vla-get-layouts VlaDoc)
(if (wcmatch (setq LayNam (strcase (vla-get-name LayFor))) (strcase LayNms))
(vlax-for ObjFor (vla-get-block LayFor)
(if
(and
(= (vla-get-objectname ObjFor) "AcDbBlockReference")
(not (vlax-property-available-p ObjFor 'Path)) ; not Xref
(wcmatch (setq LyrNam (strcase (vla-get-Layer ObjFor))) (strcase LyrNms))
(wcmatch (setq BlkNam (strcase (vla-get-Name ObjFor))) (strcase BlkNms))
(if FlgAtt (= (vla-get-hasattributes ObjFor) FlgAtt) T)
)
(setq OutLst (cons (list BlkNam LyrNam LayNam ObjFor) OutLst))
)
)
)
)
)
( (setq Ss_Tmp
(ssget "_X"
(cond
( (= :vlax-true FlgAtt) (list '(0 . "INSERT") (cons 410 LayNms) (cons 8 LyrNms) (cons 2 BlkNms) '(66 . 1)) )
( (= :vlax-false FlgAtt) (list '(0 . "INSERT") (cons 410 LayNms) (cons 8 LyrNms) (cons 2 BlkNms) '(66 . 0)) )
( T (list '(0 . "INSERT") (cons 410 LayNms) (cons 8 LyrNms) (cons 2 BlkNms)) )
)
)
)
(repeat (setq Countr (sslength Ss_Tmp))
(and
(setq VlaObj (vlax-ename->vla-object (setq EntNam (ssname Ss_Tmp (setq Countr (1- Countr))))))
(not (vlax-property-available-p VlaObj 'Path)) ; not Xref
(setq OutLst (cons (list (vla-get-Name VlaObj) (vla-get-Layer VlaObj) (DXF 410 (entget EntNam)) VlaObj) OutLst))
)
)
)
)
OutLst
)