Get Layer Index via Grasshopper

Hello,

I’m trying to move objects from one layer to another. I’m familiar with the Elefront plugin for doing this, but I would like to add layer names from a list, and not through the ‘Value Picker’ supplied by Elefront.

How could one get the Layer Index of the Layers in the Rhino document and use that information to modify the referenced objects’ layer?

Thanks,

Dan

Layer names can be retrieved with a line of python code.

add this to a python script in Grasshopper:

import Rhino
import scriptcontext

scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc

a=rs.LayerNames(sort=True)

scriptcontext.doc = ghdoc

Hello,

Thanks for the reply, this is handy. But is there a way to also access the Layer Index as well as the Layer Name?

Thanks,

Dan

There is no Layer Index but maybe you’re looking for the LayerId and that can be retrieved like this:

import Rhino
import scriptcontext

scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc

layers = rs.LayerNames(sort=True)

layerIds = []

for layer in layers:
    layerId = rs.LayerId(layer)
    layerIds.append(layerId)

scriptcontext.doc = ghdoc
1 Like

You can use a list of values in Elefront, it doesn’t have to be the value picker.

If you simply use text, Elefront will create a layer with default color and linetype settings, but these can also be modified with Define Layer, and then baked.

If you have nested layers, you’ll need to include the full path, using the “::” to indicate a step down in the level of the layer tree.