Jump to content

Copy and filter some children from a node to another node

Recommended Posts

Hi all, I have just started out learning some Houdini scripting. Currently I am needing some help for extracting wired nodes and copy them into some nodes.

Suppose this is a basic hierarchy:

    |- ...

All the sub_child nodes are already wired to the merge_node. What I had wanted to do is to extract all these sub_child nodes but without extracting their merge node.

Currently I am able to iterate and grab the children content of the some_node by doing a glob wild card command.

# This return me all similar nodes with the naming - some_node1, some_node2
nodes = hou.node('/obj').glob('some_node*')
new_node = hou.node('/obj').createNode('geo', 'new_append_node')
# Get the children contents
for child in nodes:
    hou.node.copyNodesTo(child.children(), new_node)

However, this is also copying the merge nodes from the some_nodes into this new_node, which is something I do not want. How can I filter out the merge nodes then?

I have another question too. For my line for doing the glob, is there any commands that I can implement such that not only am I checking for some_node* but at the same time, making sure they are of a specific node type, eg. if some_node1 is a custom type while some_node2 is of geo type, then it will return me some_node2 as the result if I specify that I want only geo type?

Edited by xenas

Share this post

Link to post
Share on other sites
12 hours ago, fsimerey said:


With name() method, you can get the type of your node:

hou.node('my_node').type().name() will return 'merge' if this node is a merge sop node.

Hi there, I'm afraid I may not have phrase myself correctly.. my bad!

My last question is directed when looking for the some_nodes (I think it will works for the merge node too, will try that out later!)

As my some_nodes is of a custom type, for ease of understanding, say all the some_nodes in my scene are of geo type.
While the glob command I have used, are able to return me the results of some_node1 and some_node2, but is there anyway that I can further improve my code such that it can also check if they are of geo type too and return me that some_node (geo type)?

Share this post

Link to post
Share on other sites

Sorry if this isn't what you meant, but once you have the list of nodes you can check them with a loop similar to this:





it will print a list of all nodes that are the same type as the current node


Edited by vtrvtr

Share this post

Link to post
Share on other sites
some_geos = [n for n in hou.node('/obj').glob('some_node*') if n.type().name() == 'geo']

for node in some_geos:
    non_merges = [n for n in node.children() if n.type().name() != 'merge']
    inputs_of_merges = [n.inputs() for n in node.children() if n.type().name() == 'merge']


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