How to set object name by layer name?

Hi,

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

Thanks,
Mirko

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():
    layers=rs.LayerNames()
    for layer in layers:
        objs=rs.ObjectsByLayer(layer)
        rs.ObjectName(objs,layer)
LayerNameToObject()

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

2 Likes

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)        
    Next    
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!

Please I need a rvb file to download? Didnt works

Many thanks for this extremely useful script! For my purposes the option to use the short layer name would also be useful in some cases

Based on what I can read on the RhinoScripts section of developer.rhino3d.com, it seems that LayerNames does not have a parameter for switching between the full path name and short name

Unfortunately my scripting skills are not sufficient to find an alternative solution, so any help with modifying the script to return short layer names would be much appreciated!

Hi @ddaanniieell ,

I’m pretty new at scripting, as well, but here’s a script that is in part (or whole, I can’t remember at this point) from @Helvetosaur. Has the Shortened Name version. Hope this helps some.

-Alan

ObjectNameFromLayer.py (970 Bytes)

2 Likes

Thanks @Alan_Farkas!

Works like a charm :slight_smile:

Also, I should mention why I find this script useful, in case someone else is looking around the forum for the same reason

It’s easy and quick to set up material templates in Keyshot based on object names, saving a ton of time when working on large models with many iterations. So if your Rhino model is organised using layers, applying this script will streamline the process

The thing with short layer names is that for some reason setting up material templates in Keyshot doesn’t always work when using long, full path names, at least in my experience (using KS v9)

Thanks again!

Daniel

1 Like