Yes it's possible to find all block names in a selection including nested blocks.
Try this by calling (nestedBlocks (ssget))Code - Auto/Visual Lisp: [Select]
Works like a charm!Code - Auto/Visual Lisp: [Select]
Thank you for your help dexus, also for the comments. Very helpful for me to understand how to deal with nested blocks and the objects inside them.
The following may present a more efficient alternative:Nice, seems to be a little bit faster on big drawings. Great code to learn from, thank you.Code - Auto/Visual Lisp: [Select]
) ) ) ) ) ) (cond ) ) ) ) ) lst )
I'm surprised that your code performs as expected given these lines:Why wouldn't it? It checks if that hatch I want to delete is part of the selected blocks. It's just terribly inefficient to do so for every object in every block.Code - Auto/Visual Lisp: [Select]
[...]I didn't do any optimization so it was indeed very inefficient with repeated blocks. Thanks for the improvements.
It is worth noting that this is a rather inefficient way of obtaining the referenced block names within the selection, as, for each selected block reference, the function is iterating over the components and nested components, regardless of whether the block has already been encountered in the selection. The duplicate block names are then being removed from the resulting list.
The following may present a more efficient alternative:
[...]
QuoteI'm surprised that your code performs as expected given these lines:Why wouldn't it? It checks if that hatch I want to delete is part of the selected blocks. It's just terribly inefficient to do so for every object in every block.Code - Auto/Visual Lisp: [Select]