Find+replace layer name prefix of layer, sub-layer,& sub-sub-layer

I am looking for a Python script to search the first three characters of layernames in Rhino V7 for a prefix (e.g E86--------) and replace it with another three character prefix (e.g. F90---------)

So before the script runs I would see:
v Profiles
E86001 first profile
E86002 second profile
E86003 third profile…
E86---- etc…

After the script runs I would see
v Profiles
F90001 first profile
F90002 second profile
F90003 third profile…
F90---- etc…

In some cases there are layers with sub layers that have their own sub-sub-layers
e.g.
v Profiles

E86001
E86001PVT
E86001SLT
E86001FXG

I did find a script AT ThiS link but it does not search and replace and appears to only
add a prefix to all layers and sublayers?

BATCH LAYER NAME REPLACE SCRIPT

Perhaps this could be modified ??

Many thanks

Logikman

The link in my previous post seems to be wrong
please see correctv link below

Logikman

Hi @logikman,

See if this does what you want.

replace_layer_prefix.py (1.7 KB)

– Dale

Hi Dale

Many thanks for your prompt response.
Tried your excellent script out on a test file with 68 changes in layers, sub-layers and sub-sub-layers and it worked fine !
Maybe something that should be added into the base Rhino commands at some stage ??
It would be very usefull where a range product designs have various sizes or thicknesses. The component layers can be duplicated for each range and the layers updated to reflect the size or thickness of the component.

Logiman :+1: :grinning: