Jump to content
Sign in to follow this  
tamagochy

Loop for all nodes

Recommended Posts

So i need to modify file path in all file and filecache nodes.

I made python script and it works, but the problem is it works only for selected nodes. I cant find how to loop through all nodes in houdini script to find specific ones and make changes more automatically.

Thanks!

Share this post


Link to post
Share on other sites

Here is a little snippet from an exporter I was working on. You can just review all nodes of a certain type inside a certain network path.

def childrenOfNode(node, filter):
    # Return nodes of type matching the filter (i.e. geo etc...).
    result = []
    if node != None:
        for n in node.children():
            t = str(n.type())
            if t != None:
                for filter_item in filter:
                    if (t.find(filter_item) != -1):
                        # Filter nodes based upon passed list of strings.
                        result.append('%s~%s' % (n.name(), t))
                    result += childrenOfNode(n, filter)
    return result

# Export geo based objects as RIB archives.
node_path = '/obj'
lst_geo_objs = []
nodes = childrenOfNode(hou.node(node_path),["Object geo"]) #Other valid filters are Sop, Object, cam.
for node in nodes:
    ary = node.split("~")
    if len(ary) > 0:
        node_candidate = "%s/%s" % (node_path, ary[0])
        n = hou.node(node_candidate)
        if n !=None:
            if n.isDisplayFlagSet():
                exportAsRIB(node_candidate, export_dir)

 

Share this post


Link to post
Share on other sites

Not sure if this is what you're looking for, but if you want to loop over for example all file nodes in your scene you could use hou.nodeType().

Example:

import hou

# Get sopNodeType for the file SOP
file_nodes = hou.nodeType(hou.sopNodeTypeCategory(), "file")

# Loop over all instances of the sopNodeType
for node in file_nodes.instances():
    print node.parm("file").eval()

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×