I have only dabbled with some very simple Grasshopper scripts but would like to develop something more complex and unsure where to start.
I have a file imported into Rhino which as a messy layer structure with heavily nested children layers which are not needed. I’d simply like to move all geometry on the lower level layers to a higher level.
See example image below:
I have geometry on the layer ‘Body’ at the lowest level, I’d like to move this geometry to ‘Basic Wall: STR-Conc Insitu Wall Nwt’. But this instance exists hundreds of times within this file.
Its a bit late to answer but anyway here is a functions to move objects to top level layer
import Rhino
act_doc = Rhino.RhinoDoc.ActiveDoc
def obj_to_top_layer():
# iterate over layers
for lay in act_doc.Layers:
# get all child layers
if len(str(lay).split('::')) > 1:
# check if objects on this layer
if len(act_doc.Objects.FindByLayer(lay)) > 0:
# move objects to the first parent layer
for obj in act_doc.Objects.FindByLayer(lay):
lay_first = act_doc.Layers.FindName(str(lay).split('::')[0])
obj.Attributes.LayerIndex = lay_first.LayerIndex
obj.CommitChanges()
if execute:
obj_to_top_layer()
if you want to delete all empty child layers there is this function
import Rhino
act_doc = Rhino.RhinoDoc.ActiveDoc
def delete_empty_child_lay():
act_doc.Views.RedrawEnabled = False
for lay in act_doc.Layers:
# get all child layers
if len(str(lay).split('::')) > 1:
# delete all child layers
act_doc.Layers.Delete(lay.Id,True)
if execute:
delete_empty_child_lay()
This is perfect thank you, if I have the below scenario, how would I edit this script to move to the parent layer of my choice? i.e ‘Structural Framing’ being ‘Parent level 2’?