Hi,
I'm using a few environment variables for certain parts of the pipeline. For example JOB but also some custom ones like MYRESX, MYRESY, MYSHOT etc.
Houdini picks them up correctly when running from a shell but doesn't add them to the "Variables" tab in the "Aliases and Variables..." menu. They are still there, when running echo $MYRESX in the hscript textport and they are properly evaluated in the scene. They also come across when creating a new scene from the current session. So far so good.
I tried to add them to the "Variables" menu via a start up python script (pythonrc.py) which also works fine.
shot_value = os.getenv("MYSHOT", "")
hou.hscript(f'set -g MYSHOT = "{shot_value}"')
Now they are evaluated in the scene and are visible in the Variables menu. And Deadline picks them up for rendering. Great!
But now it get's weird. When I do that, the variables disappear when creating a new scene from a houdini session, only standard variables like JOB survive.
If I don't run the python script at start up, deadline doesn't pick them up for rendering.
I can't seem to be able to achieve both. Transferring variables to a new scene from the same houdini session AND passing them to deadline for rendering.
I must be doing something wrong here, surely.
Thanks in advance!
Houdini Environment Variables handling
1931 1 0-
- sacredMerlinClub
- Member
- 4 posts
- Joined: Oct. 2024
- Offline
-
- sacredMerlinClub
- Member
- 4 posts
- Joined: Oct. 2024
- Offline
I did a bit more testing and found a workaround.
The issue is that when creating a new scene from a open houdini session it can't find the system environment variables anymore.
This will return empty
shot_value = os.getenv("MYSHOT", "")
So when running this in a 456.py script:
shot_value = os.getenv("MYSHOT", "")
hou.hscript(f'set -g MYSHOT = "{shot_value}"')
It will set MYSHOT correctly when running houdini from a shell but will return empty when creating a new scene from the open session.
I also tried reading it in like this:
shot_value = hou.getenv('MYSHOT', '')
Again, it works for a new houdini session but returns empty when creating a new scene.
It seems like, as soon as it is set as a global variable, it will be wiped completely when creating a new scene.
The workaround that worked for me was to set another local env var which I can call if the system variable returns empty. For example
shot_value = os.getenv('MYSHOT', '')
if shot_value:
hou.putenv('MYSHOT_tmp', shot_value)
hou.hscript('set -g MYSHOT = {}'.format(shot_value))
else:
myshot_tmp_value = hou.getenv('MYSHOT_tmp', '')
hou.hscript('set -g MYSHOT = {}'.format(myshot_tmp_value))
So when creating the new scene it will take the else statement and read the tmp houdini variable to set the global variable.
This feels very hacky, I'm not sure if that's the best way to do it or if there is something wrong in my overall setup. But it seems to work for now.
The issue is that when creating a new scene from a open houdini session it can't find the system environment variables anymore.
This will return empty
shot_value = os.getenv("MYSHOT", "")
So when running this in a 456.py script:
shot_value = os.getenv("MYSHOT", "")
hou.hscript(f'set -g MYSHOT = "{shot_value}"')
It will set MYSHOT correctly when running houdini from a shell but will return empty when creating a new scene from the open session.
I also tried reading it in like this:
shot_value = hou.getenv('MYSHOT', '')
Again, it works for a new houdini session but returns empty when creating a new scene.
It seems like, as soon as it is set as a global variable, it will be wiped completely when creating a new scene.
The workaround that worked for me was to set another local env var which I can call if the system variable returns empty. For example
shot_value = os.getenv('MYSHOT', '')
if shot_value:
hou.putenv('MYSHOT_tmp', shot_value)
hou.hscript('set -g MYSHOT = {}'.format(shot_value))
else:
myshot_tmp_value = hou.getenv('MYSHOT_tmp', '')
hou.hscript('set -g MYSHOT = {}'.format(myshot_tmp_value))
So when creating the new scene it will take the else statement and read the tmp houdini variable to set the global variable.
This feels very hacky, I'm not sure if that's the best way to do it or if there is something wrong in my overall setup. But it seems to work for now.
-
- Quick Links
