Nerox Posted May 30, 2011 Share Posted May 30, 2011 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, Quote Link to comment Share on other sites More sharing options...
sanostol Posted May 30, 2011 Share Posted May 30, 2011 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, Quote Link to comment Share on other sites More sharing options...
graham Posted May 30, 2011 Share Posted May 30, 2011 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. Quote Link to comment Share on other sites More sharing options...
Nerox Posted May 31, 2011 Author Share Posted May 31, 2011 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. Quote Link to comment Share on other sites More sharing options...
graham Posted May 31, 2011 Share Posted May 31, 2011 (edited) 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 May 31, 2011 by graham Quote Link to comment Share on other sites More sharing options...
garf Posted July 27, 2016 Share Posted July 27, 2016 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. Quote Link to comment Share on other sites More sharing options...
DonRomano Posted July 29 Share Posted July 29 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.