Python global expression variables

   9969   11   0
User Avatar
Member
210 posts
Joined: Jan. 2014
Offline
What are the Global expression variables for Python or where can I find them or is there a function to translate them from HScript?

lvar('') doesn't seem to work

For example:
A groupnode called test with the group name set to $OS returns test, right what it is supposed to do.
However, with the group name set to lvar('OS') it returns lvar__OS__.

I know that lvar('') is for translating local variables from HScript into Python but I havn't found any function so far that translates global variables.
User Avatar
Member
8554 posts
Joined: July 2007
Offline
for global variables use
hou.expandString()

so it will be
hou.expandString(“$OS”)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
210 posts
Joined: Jan. 2014
Offline
hm…..thanks so far, that's a bit better but not quite what I want.

My groupnode test with groupname set to expandString('$OS') returns expandString__test__ but I want it to return just test, just like the HScript command would do.
User Avatar
Member
304 posts
Joined: May 2006
Offline
Maybe I´m missing something obvious, but…

if I store the group name parameter in a variable, let´s say “gname”

then gname.eval()
returns the proper name of the group, even if you used $OS
Javier Meroño
FX TD.
User Avatar
Member
210 posts
Joined: Jan. 2014
Offline
Netvudu
if I store the group name parameter in a variable, let´s say “gname”

then gname.eval()
returns the proper name of the group, even if you used $OS


I'm not quite shure what you mean but it sounds a bit too much for what I want.
$OS is used to pass the string of an operators name to a parameter, in this case it means that the group name is the same as the nodes name. In HScript thats pretty handy since $OS is just 3 characters to type. I have my default scripting laguage set to Python and I don't wanna change this everytime to HScript when I wanna use $OS. So a short handy command/expression/function would be nice.
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
This is even bit shorter and works same as hou.expandString('$OS') :
hou.pwd().name()

But still longer then $OS hscript variant.

Attachments:
python_name.hipnc (63.0 KB)

User Avatar
Member
210 posts
Joined: Jan. 2014
Offline
hmmm….yours works. When I type it myself it doesn't.
User Avatar
Member
304 posts
Joined: May 2006
Offline
Korny Klown2
I'm not quite shure what you mean but it sounds a bit too much for what I want.
$OS is used to pass the string of an operators name to a parameter, in this case it means that the group name is the same as the nodes name. In HScript thats pretty handy since $OS is just 3 characters to type. I have my default scripting laguage set to Python and I don't wanna change this everytime to HScript when I wanna use $OS. So a short handy command/expression/function would be nice.

Ah, now I understand, sorry.
The reply I gave was oriented towards creating a python script and getting the group name.
What you want is the Python equivalent to $OS to write it in the parameter window.

What pezetko says works well, but it is indeed longer than $OS.
Two small tips (that you might already now)
-You can change the expression language just for one parameter by right-clicking and choosing “expression-Change language to Hscript”
-You can save a preset for any node. So what I would do is write this “hou.pwd().name()” or “$OS” on my node and save it as a preset so every time I create a group node I´m just one click away from it. You could even save it as the type default if you wanted to.

Hope it helps.
Javier Meroño
FX TD.
User Avatar
Member
210 posts
Joined: Jan. 2014
Offline
Netvudu
-You can change the expression language just for one parameter by right-clicking and choosing “expression-Change language to Hscript”
-You can save a preset for any node. So what I would do is write this “hou.pwd().name()” or “$OS” on my node and save it as a preset so every time I create a group node I´m just one click away from it. You could even save it as the type default if you wanted to.


Changing the expression language for one parameter or the entire node makes no difference to me since I would still have to change it everytime.
The preset trick doesn't work as well, respectively makes the the workaround even longer.
It kind of bugs me that I have to explicitly have to deal with HScript because Python is not capable of handling the same things as HScript.
Apart from that, I already mentioned that pezetkos scene works but when I type myself it doesn't. Why? Do I have to consider something special when writing Python code in a parameter? Expressions like ch('ty') work with no problem. hou.pwd().name() doesn't work at all.
User Avatar
Member
304 posts
Joined: May 2006
Offline
You just have to create a key so it´s accepts an expression and then if you click on the name of the parameter you can see it toggles between the expression and the result. Be sure to be “toggled” in the expression. Otherwise it will add some unwanted inverted commas.
Javier Meroño
FX TD.
User Avatar
Member
210 posts
Joined: Jan. 2014
Offline
I don' understand that. Why does ch() automatically create a key and I don't have to care about anything, I can just type right away where for pwd().name() I specifically have to take care that I'm in the right state of the parameter and have to create key manually. Or is it not the expression but the parameter that is different then others?….anyway…
Inconsistency all over the place. :cry: So, so confusing.
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
It's very consistent. Tomas explained it very well there:
http://forums.odforce.net/topic/15896-noob-how-to-eval-python-expression-in-group-parameter/ [forums.odforce.net]
  • Quick Links