Jump to content

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

Recommended Posts


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?


Share this post

Link to post
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

Share this post

Link to post
Share on other sites

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 

Share this post

Link to post
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:


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

Share this post

Link to post
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


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

Share this post

Link to post
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 :)

Share this post

Link to post
Share on other sites

be careful with .pressButton() though as that will trigger callback script on your parm if you have any, which may not always be desirable 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now