Jump to content

Use button to set a variable value in a menu script with python


Mzigaib

Recommended Posts

I have a simple ordered menu that have python script that has a variable 'check', I want that a button on the same node changes the value of this variable, with hscript I just put 'set -p check=1' on the callback script and I can access this variable on my menu's script, how do I do that with python?

I hope that makes sense.

 

Thanks.

Link to comment
Share on other sites

I have my function on my ordered menu list:

import os

def listDirs(check):
    result = []
    houDir = os.listdir(hou.getenv('JOB')+'/houdini')
    if check==1:
        for dir in houDir:
            result+=[dir,dir]
        return result
    else:
        result=["Nothing","Nothing"]
        return result

return listDirs(check) 

I want my button on the same node to pass a value '1' to my 'check' variable in that function, how do I do that?

I did try on a callback button:

hou.pwd().parm('dirList').listDirs(1)

But it didn't work, what am I missing?

Thanks.

Link to comment
Share on other sites

Seems like what you want is a semi-dynamic menu, which gets updated on request. You can do something along those lines:

In the menu script:

return hou.phm().my_menu_values(kwargs['node'])

In your PythonModule:

LIST_DIR = False

def my_menu_values(node):
  if not node.cachedUserData('menu_values'):
    node.setCachedUserData('menu_values', read_dir_or_something())
  
  if LIST_DIR:
  	node.setCachedUserData('menu_values', read_dir_or_something())
    
  return node.cachedUserData('menu_values')

Then in your button callback:

kwargs['node'].phm().LIST_DIR = True
# force menu to cook
kwargs['node'].parm('my_menu').menuItems()
kwargs['node'].phm().LIST_DIR = False

 

P.S. Untested

Edited by Stalkerx777
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...