Batch Rename ALL Layers + SubLayers

Hi all, @Helvetosaur, @andheum, @pascal

I need to batch rename, actually add a prefix, all layers and sublayers names of some files keeping layer ordering and layer::sublayer::subsublayer structure intact.

I found already some posts about this but did not manage to work for me:

Running Rhino v7, maybe I get errors because scripts were developed for v5/6?

I am not that into RhinoScript, Python or Grasshopper so any help is much welcome!

It is more a question of many layers than many files so manually opening a single file, performing the script and saving it individually is fine.
Many Thanks!

a modification of the script I posted should work:
rename layer.gh (8.8 KB)

before:
image
after:
image

Hi @andheum and thank you for quick reply!
I downloaded your script but could not trigger it.
Also, how do I add a Prefix to all layer names?

Is adding a prefix to just the parent layer enough, or do you need to add it to all the sub layers as well?

Hi @Helvetosaur
I need to add a prefix to all layers, sublayers, subsublayers…

I currently export my 3DM file to STP trough SpaceClaim which convert layers, sublayers to parts, subparts structured according to original Rhino hierarchy. See attached screenshot about this.
This way it is possible to export Rhino geometry to any solid modeler maintaining layers and their hierarchy.

When a Solid modeler import a STP which has parts generally create a single file for any part (ex-Rhino layer). If parts have same name, even across different files, issues may happen.

I need to add a prefix to any layer, sublayer (part, subpart) to uniquely identify them


Does this work for you?
AddPrefixToAllLayerNames.py (1.3 KB)

Right now there is no separator programmed between the typed-in prefix and the layer name. If you wish to have a separator like a dash or underscore, open the script in a text editor and change the following line:

sep=""

to (for example a dash)

sep="-"

i.e. just put the desired separator between the quote marks. Then resave the file and close it.

1 Like

THANKS a LOT!
:pray:
It works like a charm

Hi,
Does this wonderful script exist with the option of selecting specific layers/sublayers rather than all of them?

Hi Andrew,
could you modify the script to change some layers into sublayers? (using fullpath)
Example:
currLayerName = Layer1
newLayerName = Layer0::Layer1

To make Layer1 a sublayer of Layer0

Thanks in advance.