Description
Switch current “active” layer to the selected object. Allows to switch faster to a current layer when drawing, instead of looking for the right layer in the layer list.
Author and license
Script by MLAV.LAND, licensed under the GNU GPL 3 License.
Code
import rhinoscriptsyntax as rs
def switch_to_selected_object_layer():
# Check if any objects are selected
selected_objects = rs.SelectedObjects()
if not selected_objects:
print("No objects selected.")
return
# Get the layer of the first selected object
object_layer = rs.ObjectLayer(selected_objects[0])
# Switch the current layer to the object's layer
rs.CurrentLayer(object_layer)
print("Current layer switched to: " + object_layer)
# Run the function
switch_to_selected_object_layer()