How to add variables with python to the variable window?

   1817   2   0
User Avatar
Member
123 posts
Joined: Jan. 2015
Offline
Hello

I'm trying to add variables to the "Variable" window inside "Aliases and Variables"

This is the code i have so far.

import hou

fullFilepath = hou.hipFile.path()
project = fullFilepath.split("/")
step = fullFilepath.split("/")
assetType = fullFilepath.split("/")
asset = fullFilepath.split("/")
step = fullFilepath.split("/")
hou.putenv('PROJECT', project)
hou.putenv('STEP', step)
hou.putenv('ASSET_TYPE', assetType)
hou.putenv('ASSET', asset)
hou.putenv('STEP', step)


This code fixes so i can use the variables like "$SHOT" inside Houdini, but they don't get added to the list of variables :/

Does anyone have a python solution for this?

Crossing fingers for some wisdom and wise words
User Avatar
Member
1904 posts
Joined: Nov. 2006
Offline
Your issue is that hou.putenv() is only creating local variables. Only global variables show up in the Aliases and Variables window and are saved in the file. Unfortunately hou.putenv() still doesn't provide a way to create global variables so you're forced to rely on hou.hscript() calls using 'set -g' to do this via Python:
hou.hscript("set -g PROJECT = {}".format(project))
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
123 posts
Joined: Jan. 2015
Offline
Thank you for the quick reply

It worked like a charm!
  • Quick Links