Quick Python: callback script fom button parm ?

   13132   5   1
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
Trying to configure a digital asset: I want to run a callback script for a button parameter. The callback should call myFunction() from the one of the python modules that I created in the “Scripts” section of the Operator Type Properties.

I get the following error when I press the button parameter:
AttributeError: ‘module’ object has no attribute ‘myFunction’


Any idea how to setup the callback script?

Thanks!!


ps. I've already searched forums and looked at relevant doc, but probably I'm to new with python to understand everything.

Attachments:
callback error.JPG (59.5 KB)
scripts.JPG (26.9 KB)

User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
ok finally found what was wrong.
I spent two bloody hours on this dumb thing.


For future generations:

THE NAME OF THE MODULE MUST STRICTLY BE: “PythonModule”.

Don't change the name of the module (like I did) if you want to use this simple callback script for your paramater:
hou.phm().myFunc()
that calls the function myFunc() stored in your module in the Scripts section.


This is mentioned in the documentation, although not super clear:
Each digital asset type has a Python module, similar to the scene file’s hou.session module. You can use this module to store functions, classes, and objects specific to the asset type.
The module source code is stored in a section of the asset named PythonModule (on the Extra files tab of the type properties window). You can create this section manually, or Houdini will create it automatically if you create a “Python Module” event handler on the Scripts tab.
Edited by Andr - Nov. 11, 2018 21:21:10
User Avatar
Member
9 posts
Joined: April 2021
Offline
I had this exact same problem, and the fix was to use the 'PythonModule' name.

I think what got me was that I renamed the module in the scripts tab late in the day, Houdini must have kept a reference to the function around when it was previously named PythonModule because it worked for hours with the new module name. The next day I re-open Houdini and nothing is working.

So, a friendly reminder to always restart and test before calling something done!

Also thanks for posting the fix! This was like the 3rd or 4th post I've found asking about this error, but the only one that posted a solution.
User Avatar
Member
44 posts
Joined: March 2023
Offline
Here`s ashioorty howto

1. in scripts panel click add empty section
2. make syre the name ects is PythonModule
3. add function to module.
4. add function to callback scripty as follows
hou.phm().function()
User Avatar
Member
190 posts
Joined: Dec. 2016
Offline
Anyone know how to make an INT slider run a callback script on parm change ?

EDIT: it didn’t work because my function started with a capital letter
Edited by NicTanghe - Jan. 11, 2024 11:50:51
User Avatar
Member
8532 posts
Joined: July 2007
Offline
NicTanghe
Anyone know how to make an INT slider run a callback script on parm change ?
add callback script to it in Edit Parameter Interface dialog fore spare parms or Type Properties dialog for HDA parms
that will be triggered every time the value is changed manually
callback scripts are not triggered when parm value is changed by it's expression though
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links