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.