Reading through my last post, I realise how confusing my wording is...
Perhaps this is a better example to learn from:
[color=green];; This is a VLA Collection of all
;; Block definitions in the Active Drawing[/color]
(setq BlockCollection
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
[color=green]
;; Note that the ModelSpace and PaperSpace
;; objects are also block definitions containing
;; all the objects appearing in Model/Paper Space and
;; will hence appear in this collection.
;; Luckily we can identify these from other blocks
;; using the isLayout property.
[/color]
[color=green];; Now let's retrieve a specific block
;; definition from this collection
;; Prompt the user to Select a Block[/color]
(setq Entity (car (entsel "\nSelect Block: ")))
[color=green];; Convert it to a VLA-Object:[/color]
(setq VLAObject (vlax-ename->vla-object Entity))
[color=green];; Retrieve the EffectiveName, if possible
;; We use the EffectiveName, as, if the block
;; is dynamic and the visibility state of the
;; Insert (Block Reference) has changed, it will
;; appear as an Anonymous Block with name *U##[/color]
(setq BlockName
(if (vlax-property-available-p VLAObject 'EffectiveName)
(vla-get-EffectiveName VLAObject)
(vla-get-Name VLAObject)
)
)
[color=green];; Now to locate the Block Definition of the
;; selected Block Reference.
;; Note the wording: the Inserted block is a
;; Reference of the Definition.
;; Think about it this way: the Definition is the Block Blueprints
;; and the Reference or Insert is the construction
;; from these Blueprints - hence if we change the
;; block Defintion all the existing and future
;; References will reflect the change.
[/color]
(setq BlockDefintion (vla-Item BlockCollection BlockName))
[color=green];; This Block Definition is a collection in itself
;; containing all the objects making up the definition
;; With this knowledge, we can iterate through it
;; as we would with any other VLA Collection:[/color]
(vlax-for Object BlockDefinition
(print (vla-get-ObjectName object))
)