Select Objects on active Layer


#1

It would be a nice and handy command to select the objects on the current layer. I know that you can do it on the layer tab, right click, select objects/select sublayers obects. But there is no way to get them via the command line - or am I wrong?


#2

Yeah, I don’t see a native way to do this but you could create an alias something like “SelCurrentLayer” and assign the following script to it:

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

–Mitch


#3

Thank you Mitch! I should get into some basic python, it’s so useful to write little things like that :slight_smile:


#4

If you want to get sublayer objects in there as well, it’s a bit more complicated, tho…


#5

it’s a good start. one question about running the script though: i saved it as a new script and referenced the alias to the file of the script. is there another way to link a command to the script?


#6

Actually that one I just created specifically for an alias or toolbar button. All you have to do is copy the whole code, go into Options>Aliases create a new alias and paste in the code in the right hand box…
(doesn’t work, see further down)

–Mitch


#7

hmm, doesn’t seem to work that way though…
Message: unexpected token 'rs’
do i need to change something? i work with rhino 5.


#8

Did you paste all of the code into the alias?

Edit: OK, sorry, it doesn’t seem to work that way - it used to though with vb rhinoscripts ISTR… Been a long time since I tried.

So, we need to do it the old-fashioned way. Hang on a second, I will put up a complete description.


#9

Yes. I copied exactly this:

! _NoEcho _-RunPythonscript (
import rhinoscriptsyntax as rs
rs.ObjectsByLayer(rs.CurrentLayer(),True)
)
.
I don’t know if we mean the same Aliases window. Mine has two columns, the left one “Alias:”, the right one “Command Macro:”


#10

Ah, a bit too late. Thank you for taking your time! But it’s not really necessary because i can run it by referencing to the file!!


#11

Yeah, you’re right it doesn’t work, sorry.

So:
(You only need to do the first 4 steps once.)

  1. Decide on a folder somewhere where you want to save your scripts
  2. Open the python script editor using the command “EditPythonScript”
  3. In the editor, under Tools>Options, in the “Module Search Paths” window, set a complete path to the above folder
  4. Close the editor

Now:
Save any/all of your Python scripts in the above folder
In the Alias box, create your aliases as follows:
! _NoEcho _-RunPythonScript “scriptname”
(“scriptname” is the name of the script file. Enclose the name in quotes if the file name has spaces in it)
The above is also valid for toolbar buttons…

When you call the alias, the script should run.

–Mitch


#12

Works perfectly! Thanks!!
One last question, what’s the NoEcho for?
/ Edit, that was easy to google :wink:


#13

It keeps the entire script from being printed to the command line when you run it… --Mitch


#14

Below is a script to select all objects on the current layer plus all of its sublayers.

SelCurrentLayerTree.py (626 Bytes)