Use python to scroll to a specific layer

Is it possible to use python or any other scripting language in Grasshopper to scroll to a specific layer in the Layer Panel?

What do you mean by scroll, like with a mouse? Could you maybe describe a little what you would use this for?

Yes, instead of using the mouse to scroll to a specific layer…

I have files with many layers and I’m baking geometry with Elefront to specific layers.
For double checking, it would be nice if I could not just say which layer is current, visible, on, locker or whatever but if Rhino would actually jump or scroll right to the layer I chose.

PS: Layer filtering would also solve my problem. Let’s say the Panel would then only show a selection of layers which is put together in Grasshopper.

Hi @martinsiegrist,

below script seems to scroll to the layer by selecting it in the layer dialog:

import scriptcontext

def DoSomething():
    
    # set full path of the layer
    layer_path = "Layer 05::TestLayer"
    
    # find layer index
    index = scriptcontext.doc.Layers.FindByFullPath(layer_path, -1)
    if index < 0: 
        print "'{}' not found".format(layer_path)
        return
    
    # select in layer dialog, unselect others so it scrolls
    scriptcontext.doc.Layers.Select([index], True)
    
DoSomething()

Note that if the layer to select is below one or more collapsed parent layers, you’ll need to collapse them all before. Above script was tested from the build in python editor (_EditPythonScript). To run it from GH you’ll need to set the doc properly.

_
c.

4 Likes