Jump to content
Sign in to follow this  

Beginner - passing menu tokens through a callback script

Recommended Posts

Hi guys,

I recently (few days ago) started learning python and while I hit many walls I managed to find enough info on this forum and sidefx.com to help me overcome the issues.

However there's one (for now) that I can't manage to solve and it's a bit hard to explain in writing so I hope you'll have patience with me, thanks :)


Passing tokens using callback script.

I need to call a function with using the token variable from the drop down menu. For example if the user selects the first option the function get's called with a variable, if the user selects the second option the same function is called but with a different variable. From Houdini help looks like it's done using callback script to pass the token of the menu but I can't seem to make it work.


This is the python callback I have on the menu: 




paintDisplay is the drop-down menu parameter where the callback script is with the 1st token: result and the 2n one: paint



And this is the function on the HDA python module:


#Display Paint Node
def DisplayPaintMode(node):
    HDA = hou.pwd().parent().parent()
    import toolutils
    if node == 'paint':
        print 'display paint'
        paintNode = HDA.node('ObjectToDestroy/PaintFractureDensity')
        print 'display result'
        sopnode = HDA.node('ObjectToDestroy/OUT_display')
But this always prints 'display result' regardless of what option is selected from the menu.
However if I change the callback to: hou.pwd().parent().parent().hdaModule().DisplayPaintMode('paint') then it prints paint - the way it should.
So I can't find how to pass the menu tokens with the callback script.
Thanks a bunch,

Share this post

Link to post
Share on other sites

you should really use kwargs dictionary to get node, parm or parm value while within called function instead of relaying on pwd() (which can be different based on what node is current, many times not necessarily node that calls the script as you may be expectind, therefore your parm would not be correct etc)




so to get parm which called callback script you get kwargs['parm']

value of that parm kwargs['parm'].eval()

to get the node containing parameter with that callback script kwargs['node']



Edited by anim
  • Thanks 1

Share this post

Link to post
Share on other sites

Thanks for the replay Tomas,

I changed the DisplayPaintMode function to use kwargs but I still don't know how to call it using the tokens from the menu :(


From the documentation: http://www.sidefx.com/docs/houdini13.0/ref/windows/edit_parameter_interface


Parameter Description: Menu subtab

The controls on this subtab let you create a menu to set the value of the parameter. You can also use the Callback script to take actions based on menu choices.


This the part where I'm stuck.

Edited by AdrianLazar

Share this post

Link to post
Share on other sites

Managed to get it to work. I changed the menu tokens from paint and result to 1 and 2 and I did the same in the if statement and works. I think before didn't worked because the parameter wasn't sending a string as the if statement expected.


Thanks again Tomas!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this