I’m getting reacquainted with Houdini of late, and getting back to grips with Houdini Digital Assets. these are encapsulated chunks of pipeline that support all manner of neat stuff, and they’re usually full of Python scripts that do interesting things with whatever’s going into and out of them. But they can have some glitchy behavior.
One that’s now bitten me in the ass twice (6 years apart) is the fact that the HDA’s Python Module has no idea where the hell it is. It doesn’t know where it’s instantiated and it doesn’t know anything about what’s attached to it, or even its own parameters.
So best practice, near as I can tell, is if you want to evaluate parameters on the HDA node itself, you need to pass that node in from something that has a clue about it.
In HDA-land, you’ll see stuff like kwargs[“node”] all the time. Kwargs are global attributes that are accessible from anywhere in the node, except, oddly, the python module of the node itself. This is how you make buttons do stuff: if you have a python module with this method:
def foo():
foobar = hou.pwd().parm('foobar').eval()
Houdini will likely bark at you because hou.pwd() doesn’t always return the current node. Maybe it does, maybe it doesn’t. At one point, when I was writing an exporter for the Source Engine from Valve, I had a python module with a ton of parameters I needed to evaluate. Rob Vinluan from SideFX taught me this trick: put all the node’s parameters in a dictionary and access them in the Python Module as needed, like so:
parmDict = dict()
def updateParms(node):
for parm in node.parms():
parmDict.update({parm.name() : parm }
In your Python Asset’s source code, you just add hou.phm().updateParms(hou.node(‘.’)) because that will work outside the module and in the node itself. This passes the node to a function in the Python Module and sets a module-wide variable. A more pythonic way is probably to just pass the node in to Python Module methods and derive parameter values from there, because you need to assume that the Python Module is completely disconnected from its context, because at some point, it will be, and that’s when the shouting begins.