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.