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
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…
Thanks Mitch!
I am confident with macros, but I am now reading through Rhinoscripting101 …
(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)
Thanks @Alan_Farkas!
Works like a charm
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
Hi,
is it possible to do the opposite?
I would like to create a layer structure from object names.
I have a group of meshes from CFD analysis.
the only way I’ve found so far to select some particular mesh is by SelName
then I show / hide others or assign to a separate layer.
It would be easier manage this using layers.
thanks!
Sure, that should be possible. So you want to select a number of objects (or all objects in the file?) and if the object has a name, to create a layer with that name and put the object on it?
yes!
exactly this
Hmm, looks like I already have something in my library for this - try this out and see if it works for you…
ObjectNamesToLayers.py (437 Bytes)
YES!
this is what I was serching for!
Thanks a lot for this!