Select currently active layer?

Is there a quick and easy way to select the currently active layer with an alias?
I often need to join curves on the active layer, this would help a lot in that procedure.

You could do it with a script this way:

import rhinoscriptsyntax as rs
import scriptcontext as sc

def sel_current():
    layer = rs.CurrentLayer()
    objs = sc.doc.Objects
    ci = sc.doc.Layers.CurrentLayerIndex
    rs.EnableRedraw(False)
    for obj in objs:
        if obj.Attributes.LayerIndex == ci:
            rs.SelectObject(obj.Id)
    rs.EnableRedraw(True)

sel_current()

or with a two-liner:

import rhinoscriptsyntax as rs
rs.SelectObjects(rs.ObjectsByLayer(rs.CurrentLayer(),True))

That adds to any current selection (which is how native Rhino works), if you want to select only what’s on the current layer (i.e. unselect anything currently selected) it’s this:

import rhinoscriptsyntax as rs
rs.UnselectAllObjects()
rs.SelectObjects(rs.ObjectsByLayer(rs.CurrentLayer(),True))
2 Likes

Perfect, thanks!