Hey Guys,
I have a scene where I have a houdini scene created something like this below.
I want to run a python script where I can get input node of 'null1'.
If the input node type is 'merge', it should go to merge's input node.
If not, then it should return the input node.
If that merge's input is another merge, it should go to it's input & so on & so on.
This process should repeat until we get a node type which is not 'merge'.
I'm thinking it should be possible through while loop, but I'm not able to figure it out.
Can anyone please help?
Using while loop in Houdini python to filter node type
773 2 1- BinaryVinci
- Member
- 13 posts
- Joined: May 2019
- Offline
- SciTheSqrl
- Member
- 48 posts
- Joined: Aug. 2017
- Offline
hello, very simple recursion problem where for each node of type 'X', call the function again, else, add the node to the list:
source : https://www.sidefx.com/docs/houdini/hom/hou/Node.html [www.sidefx.com]
import hou startNode = hou.node("/obj/geo1/null1") nodeList = [] def findMerge(node): for input in node.inputs(): #Get a list of all node connected to the current node if "merge" == input.type().nameComponents()[2]: #We want to make sure we don't mistake an object merge for a merge by exactly comparing with the 'name' component of the node, ignoring version or namespace. findMerge(input) #if the node if a merge, we call the function. else: nodeList.append(input) #if it not a merge node, we add it do the list findMerge(startNode) #Call the function with the initial node print(nodeList)
source : https://www.sidefx.com/docs/houdini/hom/hou/Node.html [www.sidefx.com]
Edited by SciTheSqrl - Aug. 13, 2022 08:03:19
- BinaryVinci
- Member
- 13 posts
- Joined: May 2019
- Offline
-
- Quick Links