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.
Thank you very much @Helvetosaur yes, that is correct and it works great!
- I’ve tried this first
Rhino.DocObjects.Tables.LayerTable.GetSelected()
but it gave this error:
- 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]:
b_names.append(rs.LayerName(str(i)))
print(b_names)
@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
rc,test=Rhino.DocObjects.Tables.LayerTable.GetSelected(sc.doc.Layers)
@Daniel_Krajnik - maybe something like this will help:
import Rhino
import scriptcontext as sc
layers=sc.doc.Layers
rc,sel_idxs=layers.GetSelected()
if rc:
s_layer_names=[]
for idx in sel_idxs:
s_layer_names.append(layers.FindIndex(idx).Name)
print s_layer_names