catchyid Posted April 8, 2021 Share Posted April 8, 2021 hi, I have a digital asset that has menu A and menu B --> I use "Menu Script" to generate dynamically the contents of each menu, however I have this dependency : Menu B contents depend on A (so if user changes menu A selection, menu B needs to dynamically regenerate itself). Currently the only way to "refresh" menu B when A is changed is to manually select Menu B which calls its "Menu Script" (counter-intuitive for end user!). So my question : is there a way to force Menu B to run its "Menu Script" when Menu A is changed? Quote Link to comment Share on other sites More sharing options...
anim Posted April 8, 2021 Share Posted April 8, 2021 B menu should be calling the script any time you open the menu, sort of generated on the fly if needed, therefore it would pick up the changes in which situation do you see the B menu's items during changing A that you would notice it's not updated? EDIT: an, I see, you are using Normal menu so you see the label of chosen entry instead of the actual value Quote Link to comment Share on other sites More sharing options...
catchyid Posted April 8, 2021 Author Share Posted April 8, 2021 B only gets update when I click on it (to display its items). So if A changes, B won't until I click on B Quote Link to comment Share on other sites More sharing options...
anim Posted April 8, 2021 Share Posted April 8, 2021 if you call .menuItems() or .menuLabels() on such parm (which clearly evaluates the script) it would return already updated values also setting the menu items or labels directly on that parm using parm template would change them however none of those seem to have immediate UI change effect only opening the menu or also simple clicking on different node and back would show updated ones even without doing any of the above I'm not sure which clean function would refresh the UI what you can do as a workaround, at least seems to work for me is do callback script for your parm A to do this: hou.ui.paneTabOfType(hou.paneTabType.Parm).setShowParmDialog(1) which should refresh the UI and therefore force parm B to show item from updated menu B but I'd consider this a bit dirty, maybe someone knows a better way Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted April 8, 2021 Share Posted April 8, 2021 This is what I did when I needed something like this. I added a callback to my menu A and used an intermediate data storage, so when I trigger menu A, it would update the storage and trigger the callback for menu B. Example of A -> B dependency Menu A parameter callback: def changed(): # Since Menu B depends on value of Menu A, we calculate the values for Menu B in this callback and push them to the "storage" values_for_menu_b = [1, 'a', 2, 'b', 3, 'c'] # setUserData wants a string (setCachedUserData can take any Python object, but only lives within the session) kwargs['node'].setUserData('storage', str(values_for_menu_b)) # Trigger menu_b, this will cause the menu script to evaluate kwargs['node'].parm('menu_b').pressButton() Menu B menu script: def menu_items(): # eval'ing the string into a list of tuples for the menu return eval(kwargs['node'].userData('storage')) Hope this helps Quote Link to comment Share on other sites More sharing options...
catchyid Posted April 8, 2021 Author Share Posted April 8, 2021 Thank you guys I've tested calling back the menu pressButton() function and does is exactly what I want I have not tested the first solution bc my knowledge with hou.ui is limited... Once more, thank you guys for your help Quote Link to comment Share on other sites More sharing options...
anim Posted April 9, 2021 Share Posted April 9, 2021 be careful with .pressButton() though as that will trigger callback script on your parm if you have any, which may not always be desirable Quote Link to comment Share on other sites More sharing options...
papsphilip Posted October 22, 2021 Share Posted October 22, 2021 i am having a similar issue. i am using PDG to wedge an integer Menu which has a callback script. The callback script is not evaluated however when i click on the workitems. The menu item changes but the callback script never gets triggered. here is a demo file where i am using a python script TOP node after the wedge hou.node("...").parm("..").pressButton() but its not working aslo i tried directly evaluating the function in my pytohn module but that didnt work as well hou.node.("...").hdaModule().test() evaluate_callback_script.hip Quote Link to comment Share on other sites More sharing options...
papsphilip Posted October 22, 2021 Share Posted October 22, 2021 (edited) The above solution worked if i cooked the python script , BUT i wanted to output geometry after the python script in my original file so in order for the callback script to evaluate for every workitem i had to write the same python script inside the Rop geometry output-->Scripts-->Pre-Render Script set to python. is there a better way? evaluate_callback_script.hip Edited October 22, 2021 by papsphilip 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.