Python Command to Create PythonModule Event Handler

   3351   2   1
User Avatar
Member
113 posts
Joined: July 2005
Offline
I'm looking for a way to create a “PyhtonModule” event handler in a fresh HDA using Python. So far I have not found a way of doing this.

I am able to create a new section in the HDA containing Python code.
However, if I want to access the code, I must manually create a PythonModule Event Handler and add:
import toolutils
bar = toolutils.createModuleFromSection(
‘bar’, kwargs, ‘bar_PythonModule’)
if I want to access that code.
However, this sort of defeats the point.

Is there a way, using Python, to creating a PythonModule Event Handler and modify its contents?

Thanks
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
asset_definition = hou.node(“/path/to/node”).type().definition()
section = asset_definition.addSection(“PythonModule”)
asset_definition.setExtraFileOption(“PythonModule/IsPython”, True)
section.setContents(“def foo():\n print ‘test’”)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
113 posts
Joined: July 2005
Offline
Wooo Hoo!


That worked like a charm.
I had not even thought to look at the “setExtraFileOption” function.

Thank you so much!
  • Quick Links