Command for Select objects from >selected< layer


#1

[EDIT Current solution]

!
-_RunPythonScript (
import rhinoscriptsyntax as rs
cur_layer = rs.CurrentLayer()
rs.ObjectsByLayer(cur_layer, True)
)
_Group
_SelNone

Hello there,

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.

Cheers,

Peter


#2

SelLayer > Window to select layer from

-SelLayer > Command line <\Type Layer Name>

EDIT: Sorry didn’t see the scripting Tag :smile:


#3

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)

[Edit 2]

It is to be placed in this script:

    import rhinoscriptsyntax as rs

_SelectedLayer = rs.>>GetSelectedLayer<<
_ToGroup = rs.ObjectsByLayer(_SelectedLayer[, blnSelect])
rs.AddObjectsToGroup(_ToGroup)
rs.UnselectAllObjects()

Which is to replace this macro, and save another mouse click.

    !_Group
_SelNone

#4

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…

–Mitch


#5

I was not able to find it either in the Rhinoscript nor Rhino IronPython help files


#7

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.


#8

@djordje

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?


#9

I was not able to get it in full python script, because it requires a group-name to be defined.

This is what I made of it to get it to work. I just put this on a button.

    !
-_RunPythonScript (
import rhinoscriptsyntax as rs
cur_layer = rs.CurrentLayer()
rs.ObjectsByLayer(cur_layer, True)
)
_Group
_SelNone

#10

objects = rhino.ObjectsbyLayer(layer name)
Call rhino.SelectObjects(objects)


#11

@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.


#12

Hi,

Look at this python code. Does that help?

    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()

Martin


#13

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…

–Mitch


#14

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()

Martin


#15

Yep… and maybe one day we’ll have GetLayers in Python Rhinoscriptsyntax, so you can choose multiple layers…

–Mitch


#16

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)”


(Matt Gaydon) #17

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.


#18

That is correct, it is on the wishlist. Personally i would prefer if every layer gets a “IsHighlighted” property which could be queried and set.

c.


#19

Yes. Me too.


#20

IsHighlighted method - yes, please, definitely would be very useful to have access to that! +1