How to get the parent Layer?


#1

usually this works fine:

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

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

A-parent
    c-child
    d-child
B-parent
    c-child
    d-child

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


(Menno Deij - van Rijswijk) #2

If I’m not mistaken, a layer has a ParentLayerId member (at least in RhinoCommon it does http://4.rhino3d.com/5/rhinocommon/html/P_Rhino_DocObjects_Layer_ParentLayerId.htm).

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.


(Dale Fugier) #3

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 object.py - 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.


(Steve Baer) #4

This will be fixed in SR9