Jump to content

Beginner - passing menu tokens through a callback script


AdrianLazar

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: 

 

hou.pwd().parent().parent().hdaModule().DisplayPaintMode(hou.pwd().parm('paintDisplay').eval())

 

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')
        paintNode.setDisplayFlag(True)
        paintNode.setRenderFlag(True)
    else:
        print 'display result'
        sopnode = HDA.node('ObjectToDestroy/OUT_display')
        sopnode.setDisplayFlag(True)
        sopnode.setRenderFlag(True)
 
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,
-Adrian
Link to comment
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)

 

http://www.sidefx.com/docs/houdini13.0/hom/assetscripts#parameter_callback_scripts

 

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']

 

etc.

Edited by anim
  • Thanks 1
Link to comment
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
Link to comment
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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...