
Registered forum members do not see this ad.
Hello.
I'm just wondering if it's possible to create a routine that can.. well, ok:
I want to select a selection set of blocks.
For each block in SS, find name in blocks collection.
if the block has the property "count" (meaning it's nested)
get all the names that are inside that block.
If one of THOSE blocks has the property "count"
get all the names that are inside THAT block...
etc etc etc...
Seems like it should be easy, but I can't get my mind around how to make it failproof. I also don't want to list more than one of the same named item. Basically I just want to know all the blocks that are inside each block.
I've written and re-written this thing several times, and am not sure the correct way to do this. It seems like a re-cursive type deal, but I can't figure it out.![]()
Any help is appreciated. thanks.








Just want to mention, If you are trying to nest a block inside of a block and expect to get information from a nested block, Then you are wasting your time. Not sure if that is what you are doing. The problem you mention does not seem clear.Basically I just want to know all the blocks that are inside each block.
Can you elaborate on what exactly you are trying to do?
Or am I misinterpreting you?
Please explain in detail.
Thanks,
The Buzzard
I think this may work, but I reckon there are better routines out there:
Code:(defun GetObj (blk / bObj lst) (if (and (setq lst (cons blk lst)) (not (vl-catch-all-error-p (vl-catch-all-apply (function (lambda ( ) (setq bObj (vla-item (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))) blk)))))))) (vlax-for Obj bObj (and (eq "AcDbBlockReference" (vla-get-ObjectName Obj)) (setq lst (cons (vla-get-Name Obj) lst)) (getObj (vla-get-Name Obj))))) lst) (vl-load-com)
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper








Hi Buzzard,
The code needs to be provided with a block name, and if it can find that particular block in the block collection, it will iterate through the Block Object Collection and search for any Block References that make up the block (i.e, nested blocks), if it finds one, then it will get its name and recursively operate on that new name, whilst constructing a list of all the names found. Not sure if it will work or not, just a "theoretical" post.
Just gotta watch that the stack limit isn't reached when using recursive loops. I tend to only use them for small-ish tasks, as the stack limit is not too high and can sometimes be reached quite easily.
Some great info on recursive programming here.
Lee
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper




I think I understand the request:
nl contains an associative list of dotted pair atomsCode:(defun c:nbc (/ tdef fe fd bn nl) (while (setq tdef (tblnext "BLOCK" (not tdef))) (setq fe (cdr (assoc -2 tdef))) (princ (strcat "\n" (cdr (assoc 2 tdef)))) (while fe (setq fd (entget fe) fe (entnext fe)) (and (= "INSERT" (cdr (assoc 0 fd))) (setq bn (cdr (assoc 2 fd))) (if (not (assoc bn nl)) (setq nl (cons (cons bn 1) nl)) (setq nl (subst (cons bn (1+ (cdr (assoc bn nl)))) (assoc bn nl) nl)))))) (textpage) (prin1 nl) (foreach b nl (princ (strcat "\nBlock " (car b) " Is Nested In " (rtos (cdr b) 2 0) " Block(s)"))) (prin1))
( block_name . number_of_nested_direct_instances_found )
This does not count the nested depth or total number of nested occurrences in the drawing. -David
R12 (Dos) - A2K

Registered forum members do not see this ad.
You can get the information from a nested block by using the blocks collection, which contains all blocks in the drawing, and also has information on whether blocks are 'inside' that block.
Suppose I have a block for a part. Inside that part there are several more blocks. Some of the blocks inside those might have a block or two. So I want a routine that can, when I select that main part block, it get the name.. then finds the name in the block collection, and goes through the block collection for each name that resides somewhere inside that main block.
It can be done, it's just not pretty.. especially if you don't know how many blocks are nested, and you want to get all of them no matter what.
Bookmarks