Jump to content

Getting Houdini Global Vars With Python


lisux

Recommended Posts

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

Link to comment
Share on other sites

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

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).

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • 9 years later...

For those that the internet has brought them back to this thread SideFX did implement this at some point.

hou.getenv
http://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

  • Like 3
Link to comment
Share on other sites

  • 2 years later...
  • 7 months later...
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.

Link to comment
Share on other sites

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 by Stalkerx777
formatting
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...