Not sure whether this is possible, but is is there a way in python to change the selected object(s) to a highlighted layer -not an active layer?!
Thanks!
Posting what I have so far:
test.py (459 Bytes)
Not sure whether this is possible, but is is there a way in python to change the selected object(s) to a highlighted layer -not an active layer?!
Thanks!
Posting what I have so far:
test.py (459 Bytes)
Please help?!
Hi @John_Kunst,
If you have Rhino 8, you can just poke this button:
If you have Rhino 7, then this script should work.
import Rhino
import scriptcontext as sc
def ChangeToSelectedLayer():
selected_objects = list(sc.doc.Objects.GetSelectedObjects(False, False))
if not selected_objects or 0 == len(selected_objects):
print("No objects selected")
return
rc, selected_layers = sc.doc.Layers.GetSelected()
if not selected_layers or 1 != selected_layers.Count:
print("One layer must be selected")
return
layer_index = selected_layers[0]
for obj in selected_objects:
attributes = obj.Attributes.Duplicate()
attributes.LayerIndex = layer_index
sc.doc.Objects.ModifyAttributes(obj.Id, attributes, False)
sc.doc.Views.Redraw()
if __name__ == '__main__':
ChangeToSelectedLayer()
– Dale
Thank you, I’ll give this a try!
Actually, I thought about one more thing: would it be too complicated to check the currently selected layer for a child layer name ‘TEST’ and move the object to that layer? Personally I’m not at all sure how one would check a layer hierarchy through python.
It’s simply because I have files with thousands or 10s of thousands of objects, that I sometimes have to manually optimize. If I have 100 layers, and inside those I have between 10-30 layers with each having a ‘TEST’ sublayer the amount of mouse travel will quickly add up. Also the layer panel will get longer and longer… If I could keep layers collapsed, I prefer it.