Set object name by layer name with counter

Hello,

I’m looking for a script to name all objects of my scene by the name of their layer.
I found this topic. The Python script work, but i want a different name for every object, exactly like the SetObjectName command do, with the counter.
For example :
If there are 4 objects in the layer named “My_Layer”,
i want the script to name those objects : “My_Layer_1”, “My_Layer_2”, “My_Layer_3”, “My_Layer_4” and this for all layers in the scene.

If anyone can help me …
Thanks

Hello,
Does this work?

Not tested…

import rhinoscriptsyntax as rs

def LayerNameToObject():
    layers=rs.LayerNames()
    for layer in layers:
        objs=rs.ObjectsByLayer(layer)
        for i, obj in enumerate(objs):
          rs.ObjectName(obj,layer+'_'+str(i))

LayerNameToObject()
1 Like

Lovely !! It works perfectly !
Thank you so much.

1 Like