Get Parent Layer Name of an Object

I am having trouble finding a way to select just the parent layer of an object in grasshopper. I have used Human to get the lowest sublayer and full folder path, however it doesnt seem like there is a way to just isolate the Parent Layer.

Any thoughts? Thanks!

Can you clarify this? Are you looking to “get” the layer of a Rhino Object? Are you looking to “get” the parent layer of the layer that a Rhino object resides? Are you actually looking to select layers (whatever that means)?

Some clarification would be helpful.

Thanks,

– Dale

Thanks Dale.

For a bit more detail…So for any brep I select, I would like to get its parent layer. So if my layer structure is like such(Parent Layer::SubLayer1::Sublayer2)……some breps I may select are on sublayer 1, while some are on sublayer 2, but really I want to know what Parent Layer they are associated with.

I hope that’s a bit more clear. Thanks!

Hi @MLinenberger,

Here is a simple Python script that prints the layer structure of a selected Brep object:

import Rhino
import scriptcontext as sc
import System

def __print_layer_path(layer_id):
    if layer_id != System.Guid.Empty:
        layer = sc.doc.Layers.FindId(layer_id)
        if layer:
            print(layer.FullPath)
            __print_layer_path(layer.ParentLayerId) # recursive

def test_getparentlayers():
    filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select a surface or polysurface", False, filter)
    if not objref or rc !=Rhino.Commands.Result.Success: 
        return
    
    rhobj = objref.Object()
    if not rhobj:
        return
    
    layer_index = rhobj.Attributes.LayerIndex
    __print_layer_path(sc.doc.Layers[layer_index].Id)

if __name__=="__main__":
    test_getparentlayers()

Maybe this helps?

– Dale

Yes this works if I run it I run a python script within rhino. But what I am looking for is to create a component in grasshopper that I can input my breps(multiple) and then it will tell me the parent layer name as the output. Sorry if I wasnt specific enough there.

Thanks for the help again!

Take the result from Human then use Split Text component with “::” as the splitting character. Then pass results through a List Item component and get Item 0.

Will this work for you?

GetParentLayerName.gh (5.5 KB)

-Kevin

2 Likes