Iterate PandaNodes?

Hi all,
there is a method that iterate sequentially throught PandaNodes hierarchy from a given node? (like a list of nodes)

Thanks all

something like this should work (recursively):

def doSomething(nodepath):
    # do your stuff with the nodepath here
    for child in nodepath.getChildren():

You should probably check for circular/endless recursion, since PandaNodes can be connected cyclic, I think.

If you don’t want to do things recursively, you can still build a list using getChildren() on a node, its children a.s.o. and call things on all elements.

But to be honest, I can’t really think of anything I ever wanted to do with all nodes under one specific parent. If the nodes have something very specific in common and you want to call the same method on them all, it might be a better idea to wrap those NodePaths in Python classes and keep references to those objects somewhere.

As far as I know, Panda automatically checks for cyclic node graphs, so you don’t have to worry about that.

Yes, cyclic graphs are not allowed and are explicitly prevented.

You can also do:

for child in root.findAllMatches('**'):

to easily iterate over the entire hierarchy without writing a recursive function. Not that this is particularly the best way to do it; but it’s quick and easy.