Populate menu in hda in python

   2355   3   1
User Avatar
Member
13 posts
Joined: Dec. 2016
Offline
I am have an HDA and want to populate an empty dropdown menu on creation.

I am using this in my OnCreated script:

def populateMenu(node, inputList):
    hda = node.type().definition()
    ptg = hda.parmTemplateGroup()

    menuParm = node.parm("my_menu")
    template = menuParm.parmTemplate()
    template.setMenuItems([str(item) for item in range(len(inputList))])
    template.setMenuLabels(inputList)

    ptg.replace("my_menu", template)
    node.setParmTemplateGroup(ptg)

def run(kwargs):
    node = kwargs["node"]
    populateMenu(node, ["A", "B", "C"])

run(kwargs)

When I print(template) I can see that it is populated but there are no items visible in the menu on the hda.

<hou.MenuParmTemplate name='my_menu' label='Preset' menu_items'0', ‘1’, ‘2’) menu_labels'A', ‘B’, ‘C’) default_value=0 tags={ “script_callback_
language” : “python”, } is_button_strip=0 strip_uses_icons=0>

Does anyone know where I went wrong?

Thanks!
Edited by harshmallow - May 26, 2020 13:54:12
User Avatar
Member
7737 posts
Joined: Sept. 2011
Offline
Menu's aren't typically populated on creation. Menu scripts handle filling the menu with options anytime the menu needs to be drawn.
User Avatar
Member
13 posts
Joined: Dec. 2016
Offline
Do you know how I could have a list of strings in the python module and then pass that to the menu script?
User Avatar
Member
13 posts
Joined: Dec. 2016
Offline
Thanks for the info! I can just call the function normally via
hou.pwd().hdaModule().run()
  • Quick Links