How to set object name by layer name?


I want all objects on a layer to be named after their layer. Is there a script or function that does that?


No function, but a quick script could do the job… However, this will be static, if you then change the object’s layer after running the script, the object name will not automatically change… --Mitch

import rhinoscriptsyntax as rs
def LayerNameToObject():
    for layer in layers:

Note, this will act on ALL objects in the file, including hidden and locked objects…


Thanks Mitch!

I am confident with macros, but I am now reading through Rhinoscripting101 … :wink:
(initially I thought I can just create a rvb with the code you provided, but that brings an error when I try to load it)

The above code is written in Python.

To run a python script:

! _-RunPythonScript (

<paste script here>


If you want .rvb, this should work:

Option Explicit
Call LayerNameToObject()
Sub LayerNameToObject()
    Dim layers, layer, objs
    layers = Rhino.LayerNames()
    For Each layer In layers:
        objs = Rhino.ObjectsByLayer(layer)
        Call Rhino.ObjectName(objs, layer)        
End Sub

Thanks, the RunPhytonScript made it work.

Thanks a lot!

This li’l script saved me several hours of work, allowing me to quickly sort objects contained in blocks once imported into UE4.25.3.

Thank you!