Jump to content

how to update a menu items (not using menu script)


catchyid

Recommended Posts

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?

image.png.cbd4b73b8e59768de2cdf18ef8c07f6c.png

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

  • 6 months later...

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

Link to comment
Share on other sites

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 by papsphilip
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...