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)
âMitch
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)
âMitch
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
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:â
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.
So:
(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
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
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)