Jump to content

Remove nodes from node via scripting


Recommended Posts

I have just started out learning Houdini APIs and am trying to use it to do some scripting..

In the following code, I am trying to remove the file node whenever a geo node gets created.

# Create a new geo node
geo_node = hou.node('/obj').createNode('geo')
new_geo_node = geo_node.path()
# Get the children within the new geo node
check_for_children = hou.node(new_geo_node).children()
# Gets the file sop
file_node_type = hou.nodeType(hou.sopNodeTypeCategory(), "file")
# Deletes the file sop within the new geo node
for child in check_for_children:
    if child.type() == file_node_type:

I am not very sure if this logic of mine is in the correct path in terms of Houdini, because when I script it, it is pretty much python-orientated..

Is this the best approach to check and remove nodes within, from another node?

Link to comment
Share on other sites

"createNode" returns a node object so you don't need to use node.path() and then hou.node()
geo_node = hou.node('/obj').createNode('geo')
for i in geo_node.children(): i.destroy()

only one file SOP is created by default inside geo nodes so you can simplify further
geo_node = hou.node('/obj').createNode('geo')

weirdly enough, this works too

  • Like 2
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.

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