Rhino Script modification

Is there any way to modify this script export object by Layer) to not fail when nested layers are used? I just spent hours flattening a model hierarchy that I would like to preserve.

ex.rvb (1.2 KB)

So, let’s say you have a file with two parent layers, each of which has two levels of sublayers.

image

When you export by layer, do you want to preserve the layer structure? For example for the objects on ParentLayer1::SubLevel1::SubLevel2, you would get the two upper layers as blank layers and just the objects on SubLevel2.

Or, do you want to flatten the layer structure and just export the sublayers (transforming them into main layers)?

Or, do you want to export by layer family, that is to say export only parent layers as files, including the layer structure and all the objects on any of their sublayers? For example you would get two files, one with the ParentLayer1 and its sublayers (and objects), and the second with ParenatLayer2 plus sublayers and objects.

The goal would be to flatten all the layers or export by parent layer. I am refining a Revit reference file workflow. Parent layer allows easier assignment to Revit model categories.

Right now this flattening must be done manually in windows version. I work on a Mac, so imagine the trouble you have to go through to do this because the Rhino script does not work on the Mac. - a lot of rebooting into boot camp is required…

A python script would be fantastic!

You can try this one…

BatchExport3DMByParentLayer.py (2.1 KB)

It will export each parent layer as a .3dm file including all nested sublayers. The exported files will be named name ‘OriginalFilename-ParentLayerName’.

Important note: as the script relies on scripting the “Export” command which only works on selecteable objects, any objects which are on off or locked layers or which are individually locked or hidden will not be exported. So make sure everything you want is visible and unlocked before exporting. If there are no objects on a given layer, and it has no sublayers that have objects, it will not be exported either (that’s how Rhino works).

Let me know if this approaches what you want.

Wow! Thank you! This is exactly what I need. Wish I had the skills to reciprocate.

Hello @Helvetosaur
that’s great, and what if I want to export the objects in each sub layer into several files with the name of the sub layer name?

Does this work for you?
BatchExport3dmByLayer.py (1.8 KB)

it works fine, the code can already export objects in layers into one file for each layer. it’s just that I’m still looking for a way so that the resulting name is: “project name (typed manually the first time) + layer name”.
if the layer is a sublayer, then the name is: “project name (typed manually the first time) + sublayer name” (without the main layer name). sorry im new in python

The reason why this isn’t done is that sublayers can have the same names as other sublayers. Therefore if the entire sublayer name (including the main layer name which is unique) isn’t used, there would be a risk of one layer further down the list overwriting the file of another layer previously written with the same name.

I can probably modify it so that if there are duplicate file names that it renames the duplicates Filename(1), Filename(2), etc… like Windows does - I’m traveling at the moment so I won’t be able to get to it until tomorrow or Monday.