Macro to turn every object into a block

I would like to open a rhino file in inventor and have every object show up as a part. It seems the best way to do this is turning every object into a block and saving as a .stp, but that’s a lot of work turning everything into an individual block instance. Is this indeed the best way and would it be possible to create a macro to automate? never used macros before. im on rhino 7 and inventor 2022.
Thanks

-Kurt

Hi Kurt - this would be easy enough to script - replace each object with a block instance based on the bounding box center or something like that - but I am not sure that will be of much use - wouldn’t you want some hierarchy, logical blocks within blocks structure so it makes some sense in the target application?

-Pascal

Not sure what logical blocks are, but I think I get your point. i rarely use blocks and mostly rely on layers to organize components. what would be ideal would be if the script could label each individual block based on the name of the layer it’s under in rhino. so if i have 7 ribs under the layer name ribs, it could make each 1 a block called rib 1, rib 2, etc. @pascal

Yes, that is what I was getting at - some logical structure to the blocks so that they could be nested in a sensible way.

@user1089 -in the target application, if your 7 ribs are all the same, I assume what you’d really want is that each rib is an instance of the same block, otherwise in the target application you’d get seven separate and unrelated rib parts which might or might not be very good. In other words, for some of this, it would take some work on your part in Rhino (I think) for it to be really useful - that is, use blocks to build up your parts where ever that makes sense.

-Pascal

1 Like

Well, actually I think I do want individual instances because one of the main reasons for this is to populate the parts list in inventor with the correct quantities. I first selected each of the components by it’s layer and made them blocks, but then in inventor it has a qty of 1 for each components. This didn’t take too long to do, but now realizing that each part needs to be it’s own block instance is why I am asking about macros. Any advice on where to go or what to read for someone who has never written one?

can anyone point me in the right direction with this? im already stumped as to how or if it’s even possible to do this without being prompted to select each piece, which defeats the purpose. the main thing i want to do is have it run through every object automatically. is this possible?

Hi Kurt - if the block insertion points can be something predictable and simple like the bounding box centers, I can make you a script for this.

-Pascal

that would be awesome. im not sure how the block insertion point affects things, but when i did this manually for myself i just made them all 0,0,0. whatever is easier for you. thank you @pascal

if at all possible, it would be great if we can automate the block names to reflect the layer the object currently resides under. thanks again.

Hi Kurt - if there is more than one object per layer and these must be separate blocks, I’ll need to cook up a name incrementer.

@user1089 - see how this works:

Blockify.py (1.0 KB)

@user1089 - tuned up a bit to shorten the name. The incrementing is still 3 digits, I’ll take a look at that again in a bit.

@user1089 - see how the name incrementing suits you now - updated above.

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"

-Pascal

wow it works perfectly and names each item according to the layer name. thank you so much this is amazing.

1 Like

@user1089 - it occurs to me you might want to do this as part of an export process but not have the blocks and block defimitions left hanging around when done…?

-Pascal

that would save a step, but what i have more of an issue with is the file name prefix attached to each block name. instead of pipe crate 10ft6in…to just start the name with the component…feet, or floor panel, etc. @pascal
image

Yeah, it puts the whole layer hierarchy in the name (the “::” in there) I’ll take a look…

-Pascal

:pray: thank you…and less important, but if it’s not difficult to number them just 1,2,3 / individual name, ie: rib-1, rib-2, side panel-1, side panel-2,etc. right now it seems to have numbered everything 0 - 100

@user1089 - this may simplify things - it just makes the blocks temporarily for export and then removes them and their definitions.

ExportBlockified.py (1.6 KB)

See if that works in real life.

-Pascal

@pascal it sure did. B-eautiful. i really appreciate this. if you send me a crypto address, i’d be happy to send a few $ your way

1 Like

No worries, I am glad it helps, - I still think a more sophisticated exporter that uses layer hierarchy to create the blocks would be a worthy project, I have it started around here someplace.

-Pascal

I think so. I love rhino, but the company I just started at wants to use inventor at least to produce drawings. Even when I get more familiar with inventor I think I am still going to prefer rhino. Anything that would make these two ‘talk’ to each other better would be really great. If there’s a way to ‘link’ them, so that as the model updates, so do the drawings in inventor. Not sure how feasible that is, but would be a really cool feature

Hi Pascal, first of all thank you very much this is amazing.
second, I need a small change for this:
as you know in solidworks or other cad packages the BOM generated based on part numbers and their quantities. So instead of incrementing the number of same objects in a layer, I need to Replace the block.
in other words I need to have for example: 5 blocks named: M5_hex_bolt when I have a layer named: M5_hex_bolt with 5 objects in it.
Thanks in advance.