Get name/id of the currently selected layer?

Is there any way to get name or id of the currently selected layer via RhinoCommon or rhinoscriptsyntax?


This should help.

I think he wants the highlighted layer(s), not the current layer.

VB Rhinoscript has the method Rhino.SelectedLayers(), but Python rhinoscriptsyntax does not (yet). However RhinoCommon has Rhino.DocObjects.Tables.LayerTable.GetSelected() method which returns the selected layer indices.

1 Like

Thank you very much @Helvetosaur yes, that is correct and it works great!

  1. I’ve tried this first

but it gave this error:

  1. so to pass current doc’s layer table the best way for me was to:
import scriptcontext as sc
b= sc.doc.Layers.GetSelected()

and it correctly yielded a list with indices:

I’m just trying to get their names now - this doesn’t quite work, but I trust that it will get there eventually:

b= sc.doc.Layers.GetSelected()
b_names = list()
for i in b[1]:

@dale - this seems funky - is this working as it should? Certainly not how the description below seems to indicate it should work - I would have expected that it doesn’t need a supplied argument and should directly output the layer indices:

Running the following works of course, but it just seems weird to have to do this:

import Rhino
import scriptcontext as sc

@Daniel_Krajnik - maybe something like this will help:

import Rhino
import scriptcontext as sc

if rc:
    for idx in sel_idxs:
    print s_layer_names
1 Like