Div Posted August 12, 2009 Share Posted August 12, 2009 (edited) Hi, I create by python script a node and few parms on it. Then the script creates a button that should be send back the parms values in order to process them, but I can't find a way to set up an "onpress" event to it. In the Help i only see examples and functions for digital asset, hdaModule(), to call functions from the embedded module in the asset, but this doesn't work for me, as the "GUI" (a floating parameter pane) and the button are created by a python script. I create the button using hou.ButtonParmTemplate(), and at it to my node using hou.node.addSpareParmTuple(). How can I set some kind of onPress() event on my button ? Or is there a way to set the callback script for my button, i know it can be done using "editing parameter interface" but how about doing it by scripting ? Thanks a lot. Edited August 12, 2009 by Div Quote Link to comment Share on other sites More sharing options...
wolf_cub_one Posted August 12, 2009 Share Posted August 12, 2009 In the docs, there is the pressButton command to trigger a buttons callback script: http://localhost:48626/hom/hou/Parm HTH Quote Link to comment Share on other sites More sharing options...
graham Posted August 12, 2009 Share Posted August 12, 2009 You can add a callback to a parameter by setting specific tags on a ParmTemplate by using the setTags() function: my_button = hou.ButtonParmTemplate("parm", "Label") my_button.setTags({"script_callback": "print hou.pwd()", "script_callback_language": "python"}) Quote Link to comment Share on other sites More sharing options...
Div Posted August 13, 2009 Author Share Posted August 13, 2009 (edited) Thanks a lot Graham, you're definitely saving my hairs these days. I've got now another problem : I need to make the button call a function which will be a export one ( writing files etc), the problem is where can i store this function ? I thought to set the button's callback function to 'hou.session.myFunction()' and to store myFunction() in the hou.session module, but i'm stuck now on the way to add by scripting the function to the module. Edited August 13, 2009 by Div Quote Link to comment Share on other sites More sharing options...
graham Posted August 13, 2009 Share Posted August 13, 2009 White using the hou.session module is a viable option, why not just keep your function in the same python module you use to create everything? my_button.setTags({"script_callback": "import mymodule; mymodule.myfunction()", "script_callback_language": "python"}) Quote Link to comment Share on other sites More sharing options...
Div Posted August 13, 2009 Author Share Posted August 13, 2009 (edited) Because actually I didn't use any module, the shelf tool contain all the script. But you're right, I just have to create a module and import it to be able to use it both in the shelf tool and in my button's callback..... The only problem that appears to me is that to install my tool, the user will have to put 2 files in their respective directories (python module and shelf toolbar) instead of just putting the .shelf file in the toolbar directory, but that's not really a problem... I'll go for you solution, thanks again Edited August 13, 2009 by Div Quote Link to comment Share on other sites More sharing options...
mrice Posted August 13, 2009 Share Posted August 13, 2009 In that case where are you getting stuck writing the function to hou.session? Something like this should work: hou.appendSessionModuleSource('''def myFunc():\n\t#fill in some stuff\n\tpass''') Quote Link to comment Share on other sites More sharing options...
pelos Posted October 16, 2012 Share Posted October 16, 2012 very handy tricks. 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.