How to get the parent Layer?

usually this works fine:

lay = rs.ObjectLayer(guid)
parent = rs.ParentLayer(lay)

however with same name children under different parents. it sometimes fails:


is there a way to get this right without going to the object attributes via Rhino Common ?

If I’m not mistaken, a layer has a ParentLayerId member (at least in RhinoCommon it does

Also, I don’t know if you can get the full layer name, that should be something like

B-parent::c-child (with double colon in between)

If your layer name itself does not contain a double colon (which is possible) you could split the name at the double colon and get the layer hierarchy like that.

Hi Goswin,

This looks like a bug (if you will). The function should return the full path of the layer name (e.g. Default::Layer 01::Layer 02). Ideally, layer-related methods should return GUIDs, not strings. But that is another issue.

You can fix this yourself by editing - it can be found here:

%APPDATA%\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

In the ObjectLayer function, change this:

rc = scriptcontext.doc.Layers[index].Name

to this:

rc = scriptcontext.doc.Layers[index].FullPath

I’ll see that this gets on the to-do list.

1 Like

This will be fixed in SR9