executing a python script inside of a digital asset?

   4320   3   0
User Avatar
Member
81 posts
Joined: Aug. 2006
Offline
Hello!
I have a python script inside of a digital asset, I would like to call the script when the user presses a button on the digital asset.
I went to help:
https://www.sidefx.com/docs/houdini/hom/locations.html#asset_events [www.sidefx.com]

when I click on “how to reference embedded files” it goes nowhere ( broken help?)

I can execute a script stored as a parameter using a callback script:
exec hou.node(“.”).evalParm(“test”)

but how would I execute a script stored in the scripts section?
thanks much.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
In the script section create a Python Module event handler. Don't change its name, it must stay ‘PythonModule’.
Inside this script you can define and collect a series of function that you can call from the paramer.

In the callbackscript field of your paramater use the following code (rmb to set the language to python):
hou.phm().yourFunction()
Edited by Andr - March 8, 2019 16:55:16
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
it might be handy for you to pass some useful info to your function, for example which parameter is calling the function, or what node is it.

I suggest you to use the kwargs dictionary in your callback
hou.phm().yourFunction(kwargs)


and in your function:
def myfunction(kwargs):
   node = kwargs['node']
   parm = kwargs['parm']


ps. You could also simply pass a single key of the dictionary,
hou.phm().myFunction(kwargs["parm"])

but I wouldn't suggest it to avoid a possible bug [www.sidefx.com]
Edited by Andr - March 8, 2019 17:03:44
User Avatar
Member
81 posts
Joined: Aug. 2006
Offline
Andr
In the script section create a Python Module event handler. Don't change its name, it must stay ‘PythonModule’.
Inside this script you can define and collect a series of function that you can call from the paramer.

In the callbackscript field of your paramater use the following code (rmb to set the language to python):
hou.phm().yourFunction()

awesome! thanks so much, that works!
thanks all for the help.
  • Quick Links