defc0n1 Posted July 31, 2017 Share Posted July 31, 2017 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! Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted July 31, 2017 Share Posted July 31, 2017 Never tried it but it should work. After creating the variable call global like this. foo = 25 global foo Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted July 31, 2017 Author Share Posted July 31, 2017 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 Quote Link to comment Share on other sites More sharing options...
Atom Posted July 31, 2017 Share Posted July 31, 2017 (edited) Try fetching the global from within a def. foo = 25 def multFoo(passedMult): global foo return foo * passedMult Edited July 31, 2017 by Atom Quote Link to comment Share on other sites More sharing options...
f1480187 Posted July 31, 2017 Share Posted July 31, 2017 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. 1 1 Quote Link to comment Share on other sites More sharing options...
defc0n1 Posted August 1, 2017 Author Share Posted August 1, 2017 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! Quote Link to comment Share on other sites More sharing options...
georgemacin Posted January 18, 2018 Share Posted January 18, 2018 Check this simple example...python global variable Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.