Goodmorning,
I need a script to create a new layer from the name of the parts.
I need this to convert the trees of other cad to the layers of RHINO.
Could you help me?
Goodmorning,
I need a script to create a new layer from the name of the parts.
I need this to convert the trees of other cad to the layers of RHINO.
Could you help me?
See if this works:
import rhinoscriptsyntax as rs
def LayerFromName():
objects = rs.GetObjects("Select the objects to include", 0, True, True, False)
if objects:
rs.EnableRedraw(False)
for object in objects:
name = rs.ObjectName(object)
if name:
colour = rs.ObjectColor(object)
if not rs.IsLayer(name):
layer = rs.AddLayer(name, (colour))
rs.ObjectLayer(object, layer)
elif rs.IsLayer(name):
rs.ObjectLayer(object, name)
else:
print "Unnamed object found."
rs.EnableRedraw(True)
else:
print "No objects selected."
return
rs.EnableRedraw(True)
if __name__ == "__main__":
LayerFromName()
You will need to select the objects to create the layers. If you want to select all objects automatically then just change rs.GetObjects line to rs.AllObjects(). Like this:
import rhinoscriptsyntax as rs
def LayerFromName():
objects = rs.AllObjects()
if objects:
rs.EnableRedraw(False)
for object in objects:
name = rs.ObjectName(object)
if name:
colour = rs.ObjectColor(object)
if not rs.IsLayer(name):
layer = rs.AddLayer(name, (colour))
rs.ObjectLayer(object, layer)
elif rs.IsLayer(name):
rs.ObjectLayer(object, name)
else:
print "Unnamed object found."
rs.EnableRedraw(True)
else:
print "No objects selected."
return
rs.EnableRedraw(True)
if __name__ == "__main__":
LayerFromName()
Hello, @DanBayn
I am newbie in scripting and
I tried your script, and I have a question, I try to edit it to do the same thing with blocks, using their name to send them in a matching new layer, but changing ObjectName by BlockNames, gives me error on IsLayer command…
Maybe Names of block are not managed in the same way…?
Thanks for your help
Antoine
Hi Antoine,
It’s probably best to post what you have so far so I (or anyone) can take a look and offer suggestions.
Thanks,
Dan