Change Multiple Block Definitons Layer at the same time?

Hi people,

I am currently having some complications working with blocks and I was wondering if anyone could recommend a workaround for my situation, or help me develop a script that could make my life easier…

A week ago I posted at the scripting category but maybe it wasn’t the relevant category to do so.
Below I describe my current situation and problem:

  • I am currently working on a team of a couple of people, utilizing block definitions inside Rhino.
  • I often encounter layers that I do no need, but do not get purged because a block definition was defined on that layer.
  • My workflow to deal with this is, try to delete layer>get name of block that is defined there>insert command>find block name>insert it> double click to edit>change layer on which block lays.

This is already a very time cosuming workflow for a simple task , but what is worse, when you try to delete the layer, Rhino does not name all block definition that are actually there, it tells you one at a time . So if you change the layer of one block and try to delete the layer, you then get a new message telling you there is another block on that same layer!

How can I deal with this? I was thinking a script that could identify all blocks that are defined on x layer, insert them, and change them to a correct user defined layer… Is this possible?

Thanks in advance,
Shynn

If you select everything on that layer and run ChangeLayer on that selection, doesn’t that do what you want?

Hi, I am afraid not, because to select a block definition you must enter block edit.

I might be missing something…
SelBlockInstance will select the block definition. No need to enter block edit.

Mmm, I don’t want to change the layer the block is on, but the one on which it was defined. The one that shows when you enter block edit and select the geometry.

That’s the part I didn’t read in the original description. Thanks for clarifying.

Hello - are the blocks simple, not nested, and you simply want to change the layer of all the objects contained in the block to one layer that you can specify?

-Pascal

Hi Pascal, some are nested, but most of the times the problem arises because one of the simple blocks that create the bigger blocks was created on the wrong layer.

So… I mean, I guess it is probably possible to make a script for this, I just need to know what you want to do exactly - can you give me a simple (but with nesting) example of the start and end situation that you want?

-Pascal

Of course.

Here I upload both situations, hope it is clear. You will stumble across my problem if you try to delete any of the “unwanted layers” on the “start situation” Try to at least delete the “Red Blocks” sublayer from the “Unwanted” layer and you will see how tedious it can become when dealing with bigger files.

StartSituation.3dm (316.4 KB)
EndSituation.3dm (311.3 KB)

Ok, so all objects, from all blocks, go on one layer,and all the instances go on another layer. If that’s it, I should be able to help, though not right this minute - it’s a holiday here, it’s not raining, and my bike beckons…

-Pascal

Right! The instances change is not really necessary into the script, as it can easily be achieved as @wim said.

No worries, there is no rush. Go have fun! And thank you.

@ShynnSup - Here’s a quick first cut - see how it works for you. So far it is a bigger hammer - it does all embedded blocks, no questions asked other than what layers to put things on. Linked block instances are moved to the instance layer, but not the objects to the definition layer of course.

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

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

SimplifyEmbeddedBlockLayers.py (2.2 KB)

Guaranteed somewhat tested.

Note this can be fancier - you could select blocks rather than do them all, delete the empty layers; that sort of thing. It could also be made ‘macro-able’ and not show you the GetLayer dialogs… etc.

-Pascal

Hi Pascal, thanks!

I am afraid it isn’t working on my side.
I get the following error:

Message: Find() takes exactly 2 arguments (1 given)

Traceback:
  line 29, in SimplifyEmbeddedBlockLayers, "C:\Users\Shynn\Desktop\SimplifyEmbeddedBlockLayers.py"
  line 53, in <module>, "C:\Users\Shynn\Desktop\SimplifyEmbeddedBlockLayers.py"

I run the script, pressed select on the dialog, selected the object, then double clicked to select the layer. Then repeated for Instance Layer, resulting in the error message above.

It seems the script can run with no object being selected at no time, resulting in the same error message.

As a plus, could it be done to take multiple blocks at the same time?

Thanks in advance!
Shynn

Hi Shynn - if you just select a layer in the list and then OK, i.e. do not use the ‘Select’ button, just highlight a layer - does that work? I’ll deal with selecting an object to set the layer, I confess, I did not actually type that code.

-Pascal

That’s alright. But no luck that way either, I get the same error message. :sweat:

Ok, I’ll fix it - polly something dumb - it worked here on your test file.

-Pascal

Thats strange, tested it on that same file. Running Rhino 5 for now though.

Aha. OK, I’ll check.
@ShynnSup - updated above - should work in V5 now…

As is, it does all embedded blocks - you don’t get to choose - I can add selection if that is needed.

-Pascal

Yes! This is perfect. Thank you so much Pascal! Hopefully it can be useful for other too.