I’m looking for the name of the command (if it exists) to select all objects from a layer, the same functionality as right mouse clicking a layer and choosing “Select objects”. I can’t seem to find anything on this trough google nor the forums.
Mm it’s not possible to either click the layer in the Layers panel, or choose the currently selected layer? (not to be confused with “current”)
[Edit]
To clarify I wish to be able to get the name of this layer, or directly select it’s objects. And with this I mean the layer that either is already selected, or that you select IN the layer window, not in a separate popup. (separate popup causes too much searching every time you need to get the objects)
As far as I know ( someone correct me if I’m wrong), the functionality to report back the selected (highlighted) layer in the layer panel is currently not exposed either to Rhinoscript nor Rhinocommon…
I guess this could only be solved if you make that layer current (instead of one click, double click).
Then you could use the rs.IsLayerCurrent() and in that way separate the layer you are looking for.
It would be easier then right-mouse and select the option from a menu I guess. But I hope there is perhaps a ‘secret’ function to get the Selected layer?
@stjackin ok, but the problem is getting the name of the layer, right now only direct way to get a layer name I know is using the rs.CurrentLayer(), because there is no known command for “selected layer” which would improve the possibilities of where to I could take this script and others.
I don’t understand what your script would improve over the current script.
import rhinoscriptsyntax as rs
def main():
#Get all layer Names
layers = rs.LayerNames()
#If something is returned
if layers:
#Create a ComboList, which displays all layers
layer = rs.ComboListBox(layers, "Please select a layer")
#If a layer is chosen:
if layer:
#Get all the objects
object_ids = rs.ObjectsByLayer(layer)
#...and select them
rs.SelectObjects(object_ids)
main()
That was also my idea at first, but I understood he wanted to get the layer already selected in the layer panel, not look through another to find the same…
There is also GetLayer, which is even easier than using a combo list box, especially with sublayers - GetLayer has a tree view box…
Oh yes, I totally forgot about GetLayer. Much nicer.
import rhinoscriptsyntax as rs
def main():
#Select a layer
layer = rs.GetLayer("Please select a layer")
#If a layer is chosen:
if layer:
#Get all the objects
object_ids = rs.ObjectsByLayer(layer)
#...and select them
rs.SelectObjects(object_ids)
main()
As @Helvetosaur mentioned, I’ve also figured out the GetLayer command, but as he mentioned I wan’t to be able to get the already selected layer, since I will be having to go through a list of layers, I dislike the idea of finding the layers constantly in a popup instead of just clicking one layer down in my layer panel, and pressing enter to execute the same command again.
I’m hoping someone from McNeel will come with the secret command “GetSelectedLayer(s)”
Has anyone been able to access multiple selected layers from the layers panel yet. @stevebaer is it possible to get something like the suggested “GetSelectedLayer(s)” command @Peter asked for above available in as a scriptable option in Rhino Common. Please.