How to get nodes of a file in houdini using python

   3578   1   1
User Avatar
Member
4 posts
Joined: June 2018
Offline
I am making a python script which gives nodes of a houdini file . I want node of mantra which is in /out path . I can get all nodes of /out path but i want only nodes of mantra . Can anyone tell me how to get it ?
my code is given below.

import hou
all_nodes = hou.node("/out").allSubChildren()
for node in all_nodes:
   print str(node)
User Avatar
Member
2537 posts
Joined: June 2008
Offline
I have been using something like this to fetch nodes of various types.
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((n.name(), t))
                    result += childrenOfNode(n, filter)
    return result
# For /obj nodes.
node_path = '/obj'
nodes = childrenOfNode(hou.node(node_path),["Object geo"]) #Other valid filters are Sop, Object, cam.
for (name,node_type) in nodes:
    print name,node_type

# For Mantra nodes.
node_path = '/out'
nodes = childrenOfNode(hou.node(node_path),["Driver ifd"])

To discover a node type just drag a node in to the Python Shell window and print out the type.
Edited by Enivob - Nov. 6, 2018 10:20:36

Attachments:
get_type.gif (110.5 KB)

Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
  • Quick Links