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?
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)
Thank you Mitch! I should get into some basic python, it’s so useful to write little things like that
If you want to get sublayer objects in there as well, it’s a bit more complicated, tho…
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?
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)
hmm, doesn’t seem to work that way though…
Message: unexpected token 'rs’
do i need to change something? i work with rhino 5.
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.
Yes. I copied exactly this:
! _NoEcho _-RunPythonscript (
import rhinoscriptsyntax as rs
I don’t know if we mean the same Aliases window. Mine has two columns, the left one “Alias:”, the right one “Command Macro:”
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!!
Yeah, you’re right it doesn’t work, sorry.
(You only need to do the first 4 steps once.)
- Decide on a folder somewhere where you want to save your scripts
- Open the python script editor using the command “EditPythonScript”
- In the editor, under Tools>Options, in the “Module Search Paths” window, set a complete path to the above folder
- Close the editor
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.
Works perfectly! Thanks!!
One last question, what’s the NoEcho for?
/ Edit, that was easy to google
It keeps the entire script from being printed to the command line when you run it… --Mitch
Below is a script to select all objects on the current layer plus all of its sublayers.
SelCurrentLayerTree.py (626 Bytes)