AdrianLazar Posted July 5, 2014 Share Posted July 5, 2014 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 Quote Link to comment Share on other sites More sharing options...
anim Posted July 5, 2014 Share Posted July 5, 2014 (edited) 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 July 5, 2014 by anim 1 Quote Link to comment Share on other sites More sharing options...
AdrianLazar Posted July 5, 2014 Author Share Posted July 5, 2014 (edited) 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 subtabThe 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 July 6, 2014 by AdrianLazar Quote Link to comment Share on other sites More sharing options...
AdrianLazar Posted July 6, 2014 Author Share Posted July 6, 2014 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.