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...
  • 8 years later...
On 7/27/2016 at 11:41 AM, garf said:

Heya,

 

Is there a way to lock these variables so that they can only be edited via script? i.e. to prevent users going into the Variables dialog and deleting them off.

You cannot lock a variable, but one solution is to set a callback on hou.hipFileEventType.BeforeSave that overrides/sets the desired variables, so even if someone modifies them they will retrieve their value each time the file is saved.

Link to comment
Share on other sites

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