Feedback

What's your question?

By: [ Editor ] Asked

How can I list all directly and indirectly connected nodes in Houdini with Python?

is there an easy way of doing it, or do I have to run some sort of recursive loop through all out -and inputs?

thanks

Add comment viewed 212 times Latest activity 7 months ago

or Cancel

1 answer

  • 2

dan bethell [ Editor ]

There is no all-in-one HOM method for doing this but the recursive solution is relatively simple. The only gotcha when dealing with both inputs & outputs is ensuring you don't process the same node more than once (an infinite recursion).

Here is a method for getting a list of all directly and indirectly connected hou.Node objects. Note that it does not traverse expressions or parameter references.

# return all connections up & downstream
def listConnected( node, visited=None ):
    if visited is None:
        visited = []
    connected = []
    visited.append( node )
    for n in node.inputs() + node.outputs():
        if not n in visited:
            connected.append( n )
            connected += listConnected( n, visited )
    return connected

To use it just call listConnected with a hou.Node object.

>>> connections = listConnected( hou.node( "/obj/geo1/file1" ) )
NN comments
or Cancel