Python: ObjectsByLayer to select objects on sub-layers

Sorry, I should have put more thought into this before asking for help.

The LayerChildren method is what I was overlooking.

Dan

I have this in my library if it helps… --Mitch

SelLayerTree.py (1016 Bytes)

Thanks, I’ll take a look.

Dan

Hi Mitch,

I am also using a recursive function like yours for selecting objects on childlayers. But if you have a lot of sublayers with objects on it - it takes quite a while to get a list of all objects. When selecting all Objects of one layer und sublayers in the Rhino GUI it allways takes just milliseconds, compared to almost 4 seconds using recursive function.
Does anyone have an idea how it could be done in python as fast as in Rhino GUI - Layer Window? It seems not to be possible to “simulate” it using rs.Command.

Have a nice weekend!

Philip

@powerpp,

the problem is that rs.ObjectsByLayer(layer, True) will perform the selection after processing each layer and it performs a redraw. If you set it to False and instead store it`s returned list in a global variable (a list) like so

# global variable
select_objs = []
...
tmp_objs = rs.ObjectsByLayer(layer, False)
if tmp_objs: select_objs.extend(tmp_objs)
...

it should run faster. Finally perform the selection once with rs.SelectObjects(select_objs).

c.

Thanks Clement, but that does not solve my issue.
Sorry for my bad explanation - I am not really selecting objects just collecting them in a list for further steps (using rs.ObjectsByLayer (layer_name, select=False)). So rs.Redraw(False) does not help.

@powerpp, i´m able to repeat this with a larger file (4960 layers). If i select sublayers using the Layermanager 2 sec, via above script after removing all redraw calls, 20 sec. The nesting of the layer i choose is 2 levels deep and i only get the ids of 17000 objects, without selection.

@pascal, is there a test command which does what “Select Sublayer objects” does so it could be scripted via rs.Command() ? btw. a checkbox to “include sublayers” might be a good addition to the dialog which pops up when using _SelLayer.

c.