How to get paths to all parent nodes

   9480   4   3
User Avatar
Member
16 posts
Joined: Nov. 2013
Offline
How to get paths, in /obj/ level, to all parent nodes, in separate strings, with Hscript?
May be not for all. For first 10 is enough.
I knows about`opinputpath(“.”, 0)`, but its working with inputs. not with parents
Maybe this picture explain what i mean

Attachments:
Parent node.jpg (109.1 KB)

User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
I would do it in python.

Get the parent (and the parent's parent…) by refeeding the resulted parent node path into the next loop iteration until the result equals “/” (= root level).

Just append each result to a list and voilá.

If you just want the first 10 parents, you can add another break condition by counting the number of iterations.
User Avatar
Member
150 posts
Joined: May 2011
Offline
Hi,
I put a quick file together. There's a callback script on the button which executes the script from the multiline parameter. Would be cleaner to do it with a proper HDA though.

Does someone know a better way to execute python code from a string parameter? Or a way to inject this code into another python in the hda module so I can customize certain functionality without touching my DA? Similar to the way VEXpressions work.

Attachments:
inputpaths.hip (109.0 KB)

Technical Reel 2015 [vimeo.com]
User Avatar
Member
16 posts
Joined: Nov. 2013
Offline
Hi Dennis, and thanks a lot for help. This code will be great start for my houdini pythoning.
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
dennis.albus
Does someone know a better way to execute python code from a string parameter? Or a way to inject this code into another python in the hda module so I can customize certain functionality without touching my DA? Similar to the way VEXpressions work.

You can use python modules for that.

E.g. create my_module.py in custom location and put all your code into it within functions.
#my_module.py
import hou

def test():
print(hou.pwd())
print(“Testing finished”)


def findFirstParents():
#node = hou.node(“.”)
node = hou.pwd()
start = node
node_list =

while len(start.inputs()) > 0:
input = start.inputs()
node_list.append(input.path())
start = input

node.parm(“pathmulti”).set(len(node_list))

for i, path in enumerate(node_list):
node.parm(“path”+str(i+1)).set(path)

print(node_list) #for debug
return True

Then inside houdini just import it and call your functions.
# import your custom module
import imp
my_module = imp.load_source('my_module', ‘c:\Users\petr\my_module\my_module.py’)

# calling function from this module
my_module.test()

my_module.findFirstParents()

You can edit your functions independently from your HDA or even from Houdini application. So no risk of loosing your code or have couple of different versions in different locations and assets, all is in sync.
I'm using that imp.load_source() all the time.
  • Quick Links