Object names to layers (Python maybe?)

Hello everyone,

I received a file from a client, in which they “grouped” objects by giving them the same name, so you can select them by object name. Now I want to move the model to several other software, but most of them can only handle layers but not Object names. There are hundreds of objects, and about 66 different names, so I wouldn’t want to do it manually.

What I would need, is to take each object, get its name, create a layer with that name (if it doesn’t exist yet), and move the object to that layer. I would like to find a way to make this automatic, but I don’t know any programming languages (yet), and although I found several similar problems solved with python scripts, I couldn’t find a ready-made solution for this specific issue.

Can someone help me out?

Something like this should do it

import rhinoscriptsyntax as rs

objects = rs.GetObjects("Select named objects to place on appropriate layers")
unnamed = 0
for object in objects:
    object_name = rs.ObjectName(object)
    if not object_name:
        unnamed += 1
    if object_name not in rs.LayerNames():
    rs.ObjectLayer(object, object_name)
if unnamed:
    print "%i objects had no name" % (unnamed)
1 Like

I was going to say “I’m sure someone already has written one of these…” Then I looked in my own library…

ObjectNamesToLayers.py (437 Bytes)


1 Like

Wow, you guys are awesome, it works like a charm! You just saved me hours of work!

Huge Thanks!