defc0n1 0 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! Share this post Link to post Share on other sites
lukeiamyourfather 191 Posted July 31, 2017 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
defc0n1 0 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 Share this post Link to post Share on other sites
Atom 1,454 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 Share this post Link to post Share on other sites
f1480187 797 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 Share this post Link to post Share on other sites
defc0n1 0 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! Share this post Link to post Share on other sites
georgemacin 1 Posted January 18, 2018 Check this simple example...python global variable Share this post Link to post Share on other sites