“Current layer” identifies the layer the user chooses as the current layer … is there a way to identify the layer that is clicked on?
By clicked on do you mean when you select a layer and it highlights light blue?
How about this, it works with multiple at a time as well:
Graph Space:
Model Space:
__author__ = "Michael Vollrath"
__version__ = "2023.08.16"
#Made With <3 In Dallas, TX
ghenv.Component.Name = "Get Selected Layers"
ghenv.Component.NickName = "SL"
ghenv.Component.Description = "Gets the currently selected layer names from the Rhino Document"
ghenv.Component.Params.Input[0].Name ="Refresh"
ghenv.Component.Params.Input[0].NickName ="R"
ghenv.Component.Params.Input[0].Description ="Refresh Component"
ghenv.Component.Params.Output[0].Name ="Layer Names"
ghenv.Component.Params.Output[0].NickName ="Ln"
ghenv.Component.Params.Output[0].Description ="List Of Currently Highlighted Layers"
import Rhino
sel_layer_names = []
if R:
layer_index = Rhino.RhinoDoc.ActiveDoc.Layers.GetSelected()
for index in layer_index[1]:
if index:
sel_layer_name = Rhino.RhinoDoc.ActiveDoc.Layers[index].Name
sel_layer_names.append(sel_layer_name)
else:
print("No layer selected.")
Ln = sel_layer_names
ghenv.Component.Message = str(len(sel_layer_names)) + " Selected"
@michaelvollrath Thank you … it appears to work once, but the refresh doesn’t work for me? Ideally, I’d like to work when the curve or curves are selected.
So the input R is a boolean value that when True re runs the script.
If you need it to update the script when an input change is detected from a referenced curve, that needs some different logic handling that.
And just to clarify, you want to get the selected layer not the referenced curves current layer? Correct?
@michaelvollrath When I click on the curve I want to identify the layer that that curve in on … using your terminology, I want “the referenced curves current layer” … sorry for any confusion, I appreciate your help!.
Ahhh, thank you for the clarification. That is a different script all together. One moment…
EDIT:
Here you are @MJD:
Graph Space:
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
sc.doc = Rhino.RhinoDoc.ActiveDoc
layer_ids = []
for id in O:
layer_id = rs.ObjectLayer(id)
layer_ids.append(layer_id)
Ln = layer_ids
sc.doc = ghdoc
20230816_Get_Object_Layer_Names_01a.gh (5.2 KB)
FYI: In Rhino 8 WIP you can simple retrieve the layer information from the Model Object component.
You’re welcome!