Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

defc0n1

Global variable using python

Hi guys

Can you set global variables using python within an HDA? I have an ordered menu that is being populated by a python menu script. Is it possible to set a global variable from in there?

Thanks!

Share this post


Link to post
Share on other sites

Never tried it but it should work. After creating the variable call global like this.

foo = 25
global foo

 

Share this post


Link to post
Share on other sites
7 minutes ago, lukeiamyourfather said:

Never tried it but it should work. After creating the variable call global like this.


foo = 25
global foo

 

Hi Luke

Doesn't seem to work - SyntaxWarning: name 'foo' is assigned to before global declaration :(

Share this post


Link to post
Share on other sites

Try fetching the global from within a def.

foo = 25

def multFoo(passedMult):
    global foo
    return foo * passedMult

 

Edited by Atom

Share this post


Link to post
Share on other sites

Depends on what are you trying to achieve.

1. If you wanted to store something per node , with the possibility to keep the info in the hip file.

2. hou.session module, where you can store and share Python objects within the current session of Houdini.

3. HOM shortcuts to modify the current environment variables: hou.getenv(), hou.putenv() and hou.unsetenv()
It will be available for use in parameters as $MYVARNAME until you close Houdini. It will not appear in the Aliases and Variables window, however.

4. If you really want to modify HDA definition globally, you can add a Section and save definition after that.
It will be available in the Extra Files tab of the Operator Type Properties window.

Share this post


Link to post
Share on other sites
21 hours ago, f1480187 said:

Depends on what are you trying to achieve.

1. If you wanted to store something per node , with the possibility to keep the info in the hip file.

2. hou.session module, where you can store and share Python objects within the current session of Houdini.

3. HOM shortcuts to modify the current environment variables: hou.getenv(), hou.putenv() and hou.unsetenv()
It will be available for use in parameters as $MYVARNAME until you close Houdini. It will not appear in the Aliases and Variables window, however.

4. If you really want to modify HDA definition globally, you can add a Section and save definition after that.
It will be available in the Extra Files tab of the Operator Type Properties window.

Thanks for the help guys. I managed to do what I wanted by just passing around some detail attributes. Seemed much simpler!

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