Search - User list
Full Version: Python Access to aliases and global Varialbes.
Root » Technical Discussion » Python Access to aliases and global Varialbes.
amelnychuk
I can't find how the hom finds the global variables, i have some custom ones made for my scene I would like to access from Python scripts.

Word.

-Andrew
graham
You can access them a couple ways.

set MYVAR=5

You can use HOM methods to evaluate the variable values:
>>> hou.hscriptExpression(“$MYVAR”)
'5'
>>> hou.expandString(“MYVAR”)

Also, if you define the variables using something like your bashrc file you can use the os module environment stuff.

>>> os.environ
'5'
amelnychuk
dude you rule.

Thanks alot. This is exactly what I was looking for.

-Andrew
sdugaro
is there a hom interface to aliases and variables where you can get and set or do you still need to do this kind of thing?

hou.hscript(“set -g %s = %s”%(var,val))
sdugaro
prob also good to mention here that one will throw and expection if the variable isnt set while the other will just return the empty string (hom)

>>> hou.expandString(“$BLAH35”)
''
>>> hou.hscriptExpression(“$BLAH35”)
Traceback (most recent call last):
File “<console>”, line 1, in <module>
File “/net/apps/spinux1/houdini/hfs12.5.427/houdini/python2.6libs/hou.py”, line 34791, in
hscriptExpression
return _hou.hscriptExpression(*args)
OperationFailed: The attempted operation failed.
Undefined variable
graham
Nope, still nothing.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB