Jump to content

Loop for all nodes


tamagochy

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!

Link to comment
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)

 

Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...