Jump to content

Copy and filter some children from a node to another node


xenas

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:

|-obj
    |-some_node1
        |-sub_child1
        |-merge_node
    |-some_node2
        |-sub_child2
        |-merge_node
    |-geo
    |- ...

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

12 hours ago, fsimerey said:

http://www.sidefx.com/docs/houdini15.5/hom/hou/Node#type

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)?

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

 

for node in LIST_OF_NODES_FROM_GLOB:

    print(node.type().instances())

 

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

   

Edited by vtrvtr
Link to comment
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']

 

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...