So I have this python HDA that imports a python module that has all my helper functions. I want to bundle this module into my HDA definition so it's easier to distribute. Is the Extra Files tab the right place to put it?
And how would I import this module into my HDA python module? Importing it by name (i.e. “import foo” if the section in the Extra Files tab is foo.py) raises an import error. Either I'm not looking in the right places or the docs are a little thin on this.
How to refer to a python module stored in HDA's Extra Files?
9591 3 1-
- IndyZoneCo
- Member
- 77 posts
- Joined: Nov. 2007
- Offline
-
- graham
- Member
- 1926 posts
- Joined: Nov. 2006
- Offline
From a conversation I had with another developer a couple weeks ago:
If you want to break up your Python code into multiple modules, you can use other HDA sections to store those modules. For example, suppose you want to create a (sub)module named bar. You could put the following code in an HDA section named “bar_PythonModule”:
def foo():
print “This is bar.foo()!”
Then, in the PythonModule section, you would write:
import toolutils
bar = toolutils.createModuleFromSection('bar', kwargs, ‘bar_PythonModule’)
bar now appears as a submodule of hdaModule(). So, for example, you could write the following in a button callback to call the foo function:
hou.pwd().hdaModule().bar.foo()
If you want to break up your Python code into multiple modules, you can use other HDA sections to store those modules. For example, suppose you want to create a (sub)module named bar. You could put the following code in an HDA section named “bar_PythonModule”:
def foo():
print “This is bar.foo()!”
Then, in the PythonModule section, you would write:
import toolutils
bar = toolutils.createModuleFromSection('bar', kwargs, ‘bar_PythonModule’)
bar now appears as a submodule of hdaModule(). So, for example, you could write the following in a button callback to call the foo function:
hou.pwd().hdaModule().bar.foo()
Graham Thompson, Technical Artist @ Rockstar Games
-
- IndyZoneCo
- Member
- 77 posts
- Joined: Nov. 2007
- Offline
Thank you! That submodule script worked like a charm!
I'm also working on disabling a button if there's no input to the HDA instance.
I'm trying to do this with a hidden parameter that is switched on or off by an OnInputChanged event script.
From all the references I've seen, hou.pwd() in an HDA section script should evaluate to the current working node(i.e. the HDA instance calling hou.pwd()), but running “print hou.pwd()” in any section script yields the root directory /
How can I get a reference of the HDA instance inside its own section scripts?
I'm also working on disabling a button if there's no input to the HDA instance.
I'm trying to do this with a hidden parameter that is switched on or off by an OnInputChanged event script.
From all the references I've seen, hou.pwd() in an HDA section script should evaluate to the current working node(i.e. the HDA instance calling hou.pwd()), but running “print hou.pwd()” in any section script yields the root directory /
How can I get a reference of the HDA instance inside its own section scripts?
-
- graham
- Member
- 1926 posts
- Joined: Nov. 2006
- Offline
The way to do stuff like this is to use the ‘kwargs’ dictionary that is generated in these scripts. It is a dictionary that in the case of the On Input Changed script, has keys that give you access to the node, nodetype, and the input number that was changed. Give ‘print kwargs’ a try and you should see all you need.
Graham Thompson, Technical Artist @ Rockstar Games
-
- Quick Links

