Jump to content
Mzigaib

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

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.

Share this post


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

Share this post


Link to post
Share on other sites

I think the right question should be how do I access the menu module script from a command button, everywhere I look just explain how to do that If I want to access the module in a digital asset which I think it is not the case.

Share this post


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

Share this post


Link to post
Share on other sites

Thank you so much for your time to explain me that I am totally gona try that, I didn't know that phm() module.

I'll let you know what I got.

Thanks again!

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

×