Get the object layer in grasshopper

Hi, I am trying to do something I thought pretty simple but I am struggling in grasshopper: getting the object layer of one or multiple objects.

here is my file and the error message, what am I getting wrong? This works in the Rhino IDE but NOT in a grasshopper component

import Rhino

doc = Rhino.RhinoDoc.ActiveDoc

rhino_obj = doc.Objects.FindId(x)

if rhino_obj:

layer_index = rhino_obj.Attributes.LayerIndex

layer_item = doc.Layers\[layer_index\]

layer_name = layer_item.Name

print(layer_name)

a = layer_name

else:

print("Object not found in Rhino document")

With rhinoscriptsyntax I would just use rs.objectlayer(x)

Nothing of this works in grasshopper

identify layer.gh (3.9 KB)

Your script works fine with referenced geometry.

Once you internalise the geometry, it is no longer Rhino geometry so there is no layer…

Thanks Martin, but it still doesn’t for me, what could be the issue?

test object.3dm (64.3 KB)

see this is a referenced geometry, I get the GUID but not the layer name

Change the type hint to Guid

Are you sure you need this in a script? Grasshopper has native tools to retrieve the object layer.

1 Like

Thanks Martin that works! And thanks for pointing out there was a native tool too, I didn’t know! (Although it seems to give some additional string not needed, but I can cull that “model layer : “)

:cat_with_tears_of_joy:

2 Likes

Thanks Martin, had the same issue! Any idea how to get the section style?
Cheers, Julian

I have no idea

Hi Julian -

That’s not yet possible.
RH-86137 Grasshopper: Additional Layer Properties
-wim

1 Like