Extracting block hierarchy

A while back I had a Rhinoscript that could (assuming the model was cleanly set up with this in mind, the blocks being all linked or linked/embedded) extract a summary of “parts” and “subassemblies.” To do so it had to actually open up all the block source files to count the nested blocks, and open them up, etc.

I’m rewriting it in Python and wondering if it’s at all possible to do so while only looking at the top-level model? It seems not. If I find all the instance definitions that are children of a block and recursively find the children of those blocks(mostly using rs.BlockContainers, also using GetObjects on the instance definitions,) blocks nested 2+ layers below get counted again and again, I guess once for every parent up the chain. Of course I can’t just assume the extra blocks are superfluous, they could be present at more than one level, unless I could somehow test…something? Maybe the fact that InstanceDefinition.UsesDefinition and check the nest level returned?

I suppose almost any amount of complex tedious checking would be far faster than opening up every file, if an iron-clad logic exists.

Here some code using blocks by @ejnaren: https://github.com/ejnaren/rhinotools


I’m going to work on some new tools that resemble what you describe soon. (And fix the issues reported with the existing ones.)

I think this is one such tool:


– Dale

Hmm, the Rhinoscript version seems to behave differently, not 100% correct I don’t think but different.

I did get it working, the “InstanceDefinition.UsesDefinition” method seemed to be key. It does seem a little funny that is needed, I guess Rhino itself working with the blocks doesn’t really “care” about the hierarchy?

Now I did get this working basically, but I’m noticing issues. One is that it my script retrieves the name and the description of each child block, and there was one child block I forgot to set the description on, and if I edit the source file–well, the first parent up from that block file–to add it, that edit doesn’t seem to percolate up the chain.