Get layer of an object with rs.ObjectLayer(x) inside Python compnent



I want to get the layer of an object inside grasshopper with Python component using

import rhinoscriptsyntax as rs
a = rs.ObjectLayer(x)

Type hint Brep
And I get 1. Solution exception:Parameter must be a string or Guid

What’s the correct way to do this?


I think you’ll need to set the “Type hint” differently, below seems to work:


Pass "current layer" information onto grasshopper? [SOLVED]

@Bogdan_Chipara, btw. the example above uses FindId which only works in Rhino 6.



Thanks @clement,
Is it possible to use rhinoscriptsyntax ?


Thanks for mentioning that. You saved me the trouble of re-typing your code, which in itself is a waste of time, all the more so because it won’t work in Rhino 5. Can anyone provide a Rhino 5 solution? Seems like a very reasonable question to me,


@Joseph_Oster, in Rhino 5 it should be enough to use this instead:

import Rhino
obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(x)

def MyGetObjectLayer(obj):
    index = obj.Attributes.LayerIndex
    layer = Rhino.RhinoDoc.ActiveDoc.Layers[index]
    return layer.Name

a = MyGetObjectLayer(obj)



Working code would be so helpful? Tried different ‘Type hint’ values, they fail with different errors.


Unfortunately i cannot test in V5, only have GH in V6. But this also works like my first example works if Type hint = Guid:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc
obj = sc.doc.Objects.Find(x)

def MyGetObjectLayer(obj):
    index = obj.Attributes.LayerIndex
    layer = sc.doc.Layers[index]
    return layer.Name
a = MyGetObjectLayer(obj)

Maybe @piac, could post an example using rs.ObjectLayer() i could not get this to work in V6

(Tom) #10

this works! You need to feed in an Rhino Object with a “guid” parameter, not an “surface” parameter. Surface, Breps etc won’t have any information about layer, color etc…
Its the RhinoObject who holds an geometric object (GeometryBase)


@TomTom, can you post working code please? I’m just being a dilettante on this but am surprised that a working answer hasn’t been provided for this question yet.

@clement, I get the same error as before using this type hint with a ‘Geo’ param:

All other values for ‘Type hint’ give a different error:


where did you read that you should set your Type hint to Geo ?



I meant that I replaced the ‘Srf’ param with a ‘Geo’ param (which is set to a Rhino surface) - separate issue from type hint. As I said, this isn’t my issue, I’m just trying to follow along.


It also works if i do not set any Type hint for x and leave it using “No Type Hint”, but then i have to do the conversion using an ID component:



BINGO! How silly.

That also makes the OP’s version work just fine: (7.0 KB)

@TomTom, I know you said this too, I just missed it, or didn’t understand it. Thanks.


Good :wink:



Doesn’t work for me.

Type hint is no type hint. No type hint works. I can’t choose Guid as type hint.

I don’t understand what am I doing wrong.

(using rhino5)

(Giulio Piacentino) #18


this solves it; I had just made a screenshot with similar content (before Windows Update decided to take my next 2 hours)… (8.8 KB)

There is a little more info in the definition. Basically, “Type Hint” does, inside the component, the same as what a ID param + No Hint would do. This is always the case, for any param.

I hope this helps,


Giulio Piacentino
for Robert McNeel & Associates


What happens when you open this Rhino file and GH file?
python_get_layer.3dm (29.6 KB) (7.6 KB)


That didn’t work in Rhino 5. All type hint values with only a Geo param failed until a Guid param was inserted between the Geo and Python components.

(Giulio Piacentino) #22

Please open the file above ( in Rhino 5 for a working example. You’ll need, of course, to reset the ID param to an object that exists in the Rhino doc. The Guid type hint did not exist in Rhino 5, it was added in the Rhino 6 WIP. The str type hint can be used, too, but it needs a Guid (not geometry).