Jump to content
lisux

Getting Houdini Global Vars With Python

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

Share this post


Link to post
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).

Share this post


Link to post
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 :(

Share this post


Link to post
Share on other sites

Use hou.hscriptExpression instead to have a clear variable:

>> print hou.hscriptExpression("$HIPNAME")
'untilted.hip'
>>

cheers,

sy.

Edited by SYmek

Share this post


Link to post
Share on other sites
Use hou.hscriptExpression instead to have a clear variable:

>> print hou.hscriptExpression("$HIPNAME")
'untilted.hip'
>>

cheers,

sy.

Thanks symek, more clear and better

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×