Is it possible to permanently turn on "select object layer" in the layer tools?

Is it possible to turn on a setting so that each time each time I select an object, the associated layer is automatically selected?

screenshot

Just curious, because the file I was given has so many layers.

Hi Jesse - it is not, currently, in plain Rhino, but you can somewhat work around this in a simple script, attached, and it is probably possible to make a more elaborate script with an even handler that might be able to just sit there running.

HighlightLayers.py (622 Bytes)

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"
You could put that on a keyboard shortcut in Options > Keyboard or an Alias in Options > Aliases.

-Pascal

3 Likes

You are the best. Thank you Pascal!

Hi Pascal,

thank you for the little tool, nice helper.

Is it possible to start complete script at a button without to link to the hard disk? I tried this, but it doesn’t work.

-Micha

_-RunPythonScript (
..code..
)

That should work, but my experience is scripts that have this at the end to launch them:

if __name__ =="__main__":
    DefName()

do not work in a button. You need to remove the

if __name__ =="__main__":

part and just leave

DefName()

(no indentation)

Try this one in your button -
HighlightLayers-button.py (595 Bytes)

The scripts runs without error, but nothing happens. This code I used:

_-RunPythonScript (
import scriptcontext as sc
import rhinoscriptsyntax as rs

def HighlightLayers():
    
    ids = rs.SelectedObjects()
    if not ids:
        return
    
    layers = [rs.ObjectLayer(id) for id in ids]
    layers = list(set(layers))
    
    for layer in layers:
        parent = rs.ParentLayer(layer)
        while parent is not None:
            rs.ExpandLayer(parent, True)
            parent = rs.ParentLayer(parent)
            
    layers = [sc.doc.Layers.FindByFullPath(layer, -1) for layer in layers]
    sc.doc.Layers.Select(layers, True)
    
    HighlightLayers()
)

Out-dent HighlightLayers()
(same level as def…)

I tried this now, but no luck.

_-RunPythonScript (
import scriptcontext as sc
import rhinoscriptsyntax as rs

def HighlightLayers():
    
    ids = rs.SelectedObjects()
    if not ids:
        return
    
    layers = [rs.ObjectLayer(id) for id in ids]
    layers = list(set(layers))
    
    for layer in layers:
        parent = rs.ParentLayer(layer)
        while parent is not None:
            rs.ExpandLayer(parent, True)
            parent = rs.ParentLayer(parent)
            
    layers = [sc.doc.Layers.FindByFullPath(layer, -1) for layer in layers]
    sc.doc.Layers.Select(layers, True)
    
HighlightLayers()
)

Out-dent???

-Pascal

1 Like