Jump to content

python set edit/Aliases and Variables


Nerox

Recommended Posts

Hi Guy's!

One of those, 'I'm pretty sure this is possible, but it slipped my mind' things ;-0.

In the edit menu there is a Aliases and Variables page where you can define a global variable, like 'version', with a value of 'V01' which you can call by using $VERSION. I wonder: How can you edit this using python?

Searching on this topic seems rather difficult because how do you call this? 'Variable'? Well that's not going get you any where. ;-)

Hope you can help me,

Link to comment
Share on other sites

with hscript in python

hou.hscript('set -g VERSION ='+ version)

Hi Guy's!

One of those, 'I'm pretty sure this is possible, but it slipped my mind' things ;-0.

In the edit menu there is a Aliases and Variables page where you can define a global variable, like 'version', with a value of 'V01' which you can call by using $VERSION. I wonder: How can you edit this using python?

Searching on this topic seems rather difficult because how do you call this? 'Variable'? Well that's not going get you any where. ;-)

Hope you can help me,

Link to comment
Share on other sites

You use use the os.environ dictionary to set global variables directly. Alternatively you can use hou.hscript() to wrap the set function.

import os
os.environ["VERSION"] = "V01"
hou.hscript("set VERSION = 'V01'")

There is no support for actually modifying values through the Aliases and Variables dialog however.

Link to comment
Share on other sites

You use use the os.environ dictionary to set global variables directly. Alternatively you can use hou.hscript() to wrap the set function.

import os
os.environ["VERSION"] = "V01"
hou.hscript("set VERSION = 'V01'")

There is no support for actually modifying values through the Aliases and Variables dialog however.

@Sanostol: Awesome, tnx :-)

@Graham: I wonder what the point is of setting the os.environ variable, when you also use HScript to update the Aliases and Variables dialog? The primairy reason why I would like to set the variable is to be able to call it in a file path for a version folder like: 'filepath/$VERSION/filename.$F4.exr' for instance.

Link to comment
Share on other sites

Sorry about my lackluster response. I was kind of out of it when I was writing that and didn't fully read/think about what you were asking.

Setting variables using os.environ is pretty much equivalent with the hscript set command, except when it comes to global variables with the -g option. There is no nice HOM way of doing it directly and you do need to wrap the hscript command with -g modifier in hou.hscript().

However, global variables aside, the above 2 commands were exactly equivalent. They both result in the exact same variable that is usable in all the same places. However, since they are not global they do not persist after the session has ended.

Edited by graham
Link to comment
Share on other sites

  • 5 years later...

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