@ivelin.peychev, just FYI, rs.Sleep
is calling Rhino.RhinoApp.Wait()
.
_
c.
@ivelin.peychev, just FYI, rs.Sleep
is calling Rhino.RhinoApp.Wait()
.
_
c.
Oh, I thought you meant the Time.Sleep()
Hi @ivelin.peychev,
i did. rs.Slee
p does both, the timeout and keeping the message pump alive using Wait()
. To ignore the timeout i usually set it to zero like this: rs.Sleep(0)
.
_
c.
Hi all,
I am trying to write a recursive function in GhPython for grabbing all the sublayers of any given layer.
Here is the code that I have. It is extremely slow, but seems to work. Any ideas of how to do this smarter?
def recursivelyFetchSublayers(layers):
allSublayers =
if len(layers) > 0:
for layer in layers:
if layer.GetChildren():
sublayers = list(layer.GetChildren())
if len(sublayers) > 0:
for sublayer in sublayers:
allSublayers.append(sublayer)
if sublayer.GetChildren():
subSublayers = recursivelyFetchSublayers(sublayers)
if subSublayers:
for sublayer in subSublayers:
allSublayers.append(sublayer)
if len(allSublayers) > 0:
return allSublayers
else:
return
I realized that it was just the printout that was really slow, the code runs fine. Here is a working gh.py component.
201016_RecursiveTestDoc.3dm (332.7 KB)
201026_RecursivelyFetchChildLayers_v0.0_AMJ.gh (5.7 KB)
Hi Alex, you shouldnât need recursion for this. Hereâs simple approach: checking if the parent layer name is in the full path of the layers in the Rhino document, and then grabbing the âleafâ level layer if it is:
Ah, interesting!
My goal for this is to take any given layer, and force all of its sublayers (with unknown depth) to be either 1) Turned on
2) Checked against a list of names and turned on if it matches the name, and turned off if it does not.
The problem I am having is that I need to control the sequence of these âturn onâ actions because it is impossible to turn on a layer when the parent layer is off.
Can you imagine a way that I could use the approach youâre proposing in order to create a hierarchical structure of layers where I can start at the highest level of hierarchy and then work my way downwards?