Python Access to aliases and global Varialbes.

   5564   5   2
User Avatar
Member
15 posts
Joined: Jan. 2010
Offline
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
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
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'
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
15 posts
Joined: Jan. 2010
Offline
dude you rule.

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

-Andrew
User Avatar
Member
380 posts
Joined: July 2005
Offline
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))
User Avatar
Member
380 posts
Joined: July 2005
Offline
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
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
Nope, still nothing.
Graham Thompson, Technical Artist @ Rockstar Games
  • Quick Links