Select Objects by Layer rs.ObjectsByLayer

Hello,

I’m trying to make a very small script that selects objects based on their layer name in python.

import rhinoscriptsyntax as rs

if run is True:
    rs.ObjectsByLayer(layer_name, select=False)
    x = layer_name

I thought it would be pretty straightforward but I am very confused right now.

I’d appreciate if you point out any mistakes here.

Thank you.

curves.3dm (24.9 KB)
selectobjectbylayername.gh (4.5 KB)

Have you tried select=True, it seems that is needed to select the objects?
And also, the variable ‘layer_name’ is not defined at all it seems.

There were a few other problems, but this seems to work

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

sc.doc = Rhino.RhinoDoc.ActiveDoc
layer_name = x

if run is True:
    rs.ObjectsByLayer(layer_name, select=True)

sc.doc = ghdoc
1 Like

Thank you very much @menno sir.

It was a good lesson regarding ActiveDoc command.
Indeed, it works very well now.

Have a great day!

Kind regards,
Amaraa.