replacing HDA's menu parameter with Python, resets variables

   1126   1   1
User Avatar
Member
43 posts
Joined: Jan. 2012
Offline
Hi,

I started using Python in Houdini just recently, perhaps this is something basic I am missing.

I want to update menu parm with some Python logic when SOP is created. Then each time menu is being changed(clicked and selected new value), I do another logic.

The problem is, whenever I do setParmTemplateGroup() on HDA object, some variables are being changed. I dont get whats going on. Please see attached hda and code. If you bypass setParmTemplateGroup() line, it works fine, x=20. If I update menu parm with new values/labels, x=10, even tho it was set to 20 onCreated.

Thanks!

import hou

x = 10
labelList = ["one", "two", "three"]
itemList = ["one", "two", "three"]

def updateUI(node, myitemList, mylabelList):
    
    parm = node.parm("menuParm")
    hda = node.type().definition()
    
    ptg = hda.parmTemplateGroup()
    
    menuParm = node.parm("menuParm")
    template = menuParm.parmTemplate()
    template.setMenuItems(myitemList)
    template.setMenuLabels(mylabelList)
    
    ptg.replace("menuParm", template)
    
    hda.setParmTemplateGroup(ptg)
        
        
def changedMenu():
    global x
    print ("changed menu: " + str(x))
    
def onCreated(node):
    global x, itemList, labelList
    print ("on created: " + str(x))
    x = 20
    print ("on created value updated: " + str(x))
    updateUI(node, itemList, labelList)
    print ("after updated UI: " + str(x))

Attachments:
menuParm.hda (6.6 KB)

Michal Tas Maciejewski @ Weta Digital
User Avatar
Member
43 posts
Joined: Jan. 2012
Offline
bump
Michal Tas Maciejewski @ Weta Digital
  • Quick Links