Originally Posted by
tufofi
again.. this does nothing for nested blocks.
I want a selection set that includes all blocks and nested blocks with attributes
That's impossible. You can't get a selection set of nested ANYTHINGs. You can only get selection sets of entities directly drawn in Model / Paper Space.
To obtain access to the entities inside blocks you need to either use nentsel to pick one at a time. Or go into the block's definition:
Code:
(setq bdata (tblsearch "BLOCK" "BlockName")
;; Get 1st internal entity
(setq ename (cdr (assoc -2 bdata)))
;; Step through all internals
(while ename
;; Do whatever you want with that ename. It can be anything from lines,
;; to attribute definitions, to other block references.
(setq ename (entnext ename)) ;Get next internal
)
Note there is only one set of these entities per block NAME. Even if your block is copied 1,000,0000 times there's still only one definition - thus only one set of internal entities.
A further note about attributes is that these are special "linked" entities. They always follow the block REFERENCE. Note the ATTDEF's inside the block are the attribute DEFINITIONS, not the attribute values. This can again be seen similar to the difference between block definitions and block references.
To obtain the attribute values of a block reference use entnext after you've got the block reference's (INSERT's) ename:
Code:
;; Get the 1st block from the selection set
(setq blk_ename (ssname ss 0))
;; Get the entity following it
(setq att_ename (entnext blk_ename))
;; Loop until the next entity is no longer an attribute
(while (and att_ename ;Check if entity exists
(setq att_data (entget att_ename)) ;Get its DXF data
(eq (cdr (assoc 0 att_data)) "ATTRIB") ;Check if attribute
)
;; Do whatever you want with the current attribute
(setq att_ename (entnext att_ename)) ;Get the next entity
)
What you can do is using the above methods to step through the block definitions and / or the attributes following each block reference, you can add them to a list of enames. In this way you can use nth in much the same way as you'd use ssname.