lisux Posted December 28, 2007 Share Posted December 28, 2007 Hi houdiniks I want to get some global vars from my Houdini session in a python script. I can use hscript into python with for example: hou.hscript("echo $JOB")[0][:-1] But I guess there are something in the HOM API to get the environment variables of the current session. Somebody can drop some light on this? Thanks Quote Link to comment Share on other sites More sharing options...
Jason Posted December 28, 2007 Share Posted December 28, 2007 Hi houdiniksI want to get some global vars from my Houdini session in a python script. I can use hscript into python with for example: hou.hscript("echo $JOB")[0][:-1] But I guess there are something in the HOM API to get the environment variables of the current session. Somebody can drop some light on this? Thanks Nope, those HOM functions have not been implemented, I'm afraid (I've asked for them a few times myself). You're stuck with running hscript commands from HOM right now. Try running "set" without args to get the full list. Unfortunately you get user variables (like $MYVAR) alongside the special variables like ($F). Quote Link to comment Share on other sites More sharing options...
lisux Posted December 28, 2007 Author Share Posted December 28, 2007 Nope, those HOM functions have not been implemented, I'm afraid (I've asked for them a few times myself). You're stuck with running hscript commands from HOM right now. Try running "set" without args to get the full list. Unfortunately you get user variables (like $MYVAR) alongside the special variables like ($F). A pity, I think that is very logical to have a dictionary for all the environment variables defined into the hou object. And even worse, using hou.hscript() from the python shell sometimes freezes or creates some refreshing problems to the panel Quote Link to comment Share on other sites More sharing options...
symek Posted December 28, 2007 Share Posted December 28, 2007 (edited) Use hou.hscriptExpression instead to have a clear variable: >> print hou.hscriptExpression("$HIPNAME") 'untilted.hip' >> cheers, sy. Edited December 28, 2007 by SYmek Quote Link to comment Share on other sites More sharing options...
lisux Posted December 28, 2007 Author Share Posted December 28, 2007 Use hou.hscriptExpression instead to have a clear variable: >> print hou.hscriptExpression("$HIPNAME") 'untilted.hip' >> cheers, sy. Thanks symek, more clear and better Quote Link to comment Share on other sites More sharing options...
Jason Posted December 29, 2007 Share Posted December 29, 2007 If you chorus with us and ask on SESI's site for the HOM variable functions to be added, perhaps they'll prioritize it for development sooner rather than later. Nice tip, syMEK. Quote Link to comment Share on other sites More sharing options...
graham Posted January 2, 2008 Share Posted January 2, 2008 The slightly differenty way is to use hou.expandString('$HIPNAME') Also, if you only need system environment variables you can also use things like os.environ to get a dictionary of them. import os os.environ['HIP'] Not quite the same thing but I just thought I'd throw it in. 1 Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted November 16, 2017 Share Posted November 16, 2017 For those that the internet has brought them back to this thread SideFX did implement this at some point. hou.getenvhttp://www.sidefx.com/docs/houdini/hom/hou/getenv hou.putenv()http://www.sidefx.com/docs/houdini/hom/hou/putenv.html hou.unsetenv()http://www.sidefx.com/docs/houdini/hom/hou/unsetenv.html 3 Quote Link to comment Share on other sites More sharing options...
galagast Posted September 5, 2020 Share Posted September 5, 2020 Hi, apologies for resurrecting this. The current functions does allow me to grab the Houdini Global Variables. But is there a way to get a list of these? os.environ works, but I'm only after the Houdini Global Variables currently in my scene >_< Quote Link to comment Share on other sites More sharing options...
fxartist420 Posted April 30, 2021 Share Posted April 30, 2021 On 9/5/2020 at 5:46 AM, galagast said: Hi, apologies for resurrecting this. The current functions does allow me to grab the Houdini Global Variables. But is there a way to get a list of these? os.environ works, but I'm only after the Houdini Global Variables currently in my scene >_< Hey Jeff! Did you find a solution for this?? I'm trying to do the same and got stuck. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted May 3, 2021 Share Posted May 3, 2021 (edited) I don't think there's a way to get the list of hip variables. A quick and dirty solution that comes in mind is parsing the text block of the hip file. In shell it would be: strings scene.hip | grep 'set -g' Same can be done from within Houdini with Python given the hip has been saved: import re with open(hou.hipFile.path(), 'rb') as f: for var, val in re.findall(r".*set -g (.+?)\s=\s\'(.*)\'", f.read()): print(var, val) Edited May 3, 2021 by Stalkerx777 formatting Quote Link to comment Share on other sites More sharing options...
symek Posted May 3, 2021 Share Posted May 3, 2021 3 hours ago, Stalkerx777 said: Same can be done from within Houdini with Python given the hip has been saved or just hou.hscript("setenv -s") and since we are not valetudinarians : cpio &> /dev/null -D /tmp/ -i < scene.hip && fgrep "set -g" /tmp/.variables hehe. 2 Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted May 4, 2021 Share Posted May 4, 2021 17 hours ago, symek said: or just hou.hscript("setenv -s") and since we are not valetudinarians : cpio &> /dev/null -D /tmp/ -i < scene.hip && fgrep "set -g" /tmp/.variables hehe. Aaha, nice! 1 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.