Expressions python scripting
2001 5 1- Louise Cypher
- Member
- 1 posts
- Joined: 7月 2015
- Offline
Hi
I'm moving from maya to houdini, and I have question about expressions.
See attached screenshot:
It is possible to modify “spine_pelvis_rot” from WITHIN expression “Reset” ?
I know how can I get the value of spine_pelvis_rot (ch(“spine_pelvis_rot”)), but it is possible to set one ?
For example set spine_pelvis_rot and ChestRot to be 0 when ‘Reset’ is clicked ?
I'v searched houdini help, but found only examples of how to fetch value, newer how to set specific one.
I'm moving from maya to houdini, and I have question about expressions.
See attached screenshot:
It is possible to modify “spine_pelvis_rot” from WITHIN expression “Reset” ?
I know how can I get the value of spine_pelvis_rot (ch(“spine_pelvis_rot”)), but it is possible to set one ?
For example set spine_pelvis_rot and ChestRot to be 0 when ‘Reset’ is clicked ?
I'v searched houdini help, but found only examples of how to fetch value, newer how to set specific one.
- tamte
- Member
- 8590 posts
- Joined: 7月 2007
- Online
create callback script for your Reset button
(not sure what the real name of your Snake L/R is called, so let me call it snake_lr)
python callback on Reset button would be something like:
you can do this as a function in hdaModule if your node is an hda and then just call that function in the parameter callback
or if you want to use it directly in the parameter callback you can compress it into one line like this
or
(not sure what the real name of your Snake L/R is called, so let me call it snake_lr)
python callback on Reset button would be something like:
node = kwargs['node'] parm = node.parm('snake_lr').getReferencedParm() # to get the actual referenced parameter driving your snake_lr parameter parm.set(0.0) # to set to 0.0 # or you can do parm.revertToDefaults() to revert to defaults
you can do this as a function in hdaModule if your node is an hda and then just call that function in the parameter callback
or if you want to use it directly in the parameter callback you can compress it into one line like this
node = kwargs['node'];parm = node.parm('snake_lr').getReferencedParm();parm.set(0.0)
node = kwargs['node'];parm = node.parm('snake_lr').getReferencedParm();parm.revertToDefaults()
Edited by tamte - 2020年3月25日 03:03:32
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- mariusz.szaflik
- Member
- 2 posts
- Joined: 3月 2020
- Offline
tamte
create callback script for your Reset button
(not sure what the real name of your Snake L/R is called, so let me call it snake_lr)
python callback on Reset button would be something like:node = kwargs['node'] parm = node.parm('snake_lr').getReferencedParm() # to get the actual referenced parameter driving your snake_lr parameter parm.set(0.0) # to set to 0.0 # or you can do parm.revertToDefaults() to revert to defaults
you can do this as a function in hdaModule if your node is an hda and then just call that function in the parameter callback
or if you want to use it directly in the parameter callback you can compress it into one line like thisornode = kwargs['node'];parm = node.parm('snake_lr').getReferencedParm();parm.set(0.0)node = kwargs['node'];parm = node.parm('snake_lr').getReferencedParm();parm.revertToDefaults()
Something is wrong (or I'v put the script in he wrong place) but it shows something like this: (script language is set to python)
I'm missing some imports ? (from what I'v read in help kwargs should be accesible, so this is probably my fault :/)
- tamte
- Member
- 8590 posts
- Joined: 7月 2007
- Online
well, yes, there is no kwargs dictionary passed to expressions and you don't want it as expression since that'd potentially be run a lot of times, set it as Parameter Callback script as mentioned
https://www.sidefx.com/docs/houdini/hom/locations.html#parameter_callback_scripts [www.sidefx.com]
https://www.sidefx.com/docs/houdini/hom/locations.html#parameter_callback_scripts [www.sidefx.com]
Edited by tamte - 2020年3月25日 18:20:39
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- mariusz.szaflik
- Member
- 2 posts
- Joined: 3月 2020
- Offline
I'm still strugling with it, as You mentioned I'v created callback function:
and the expresion looks like this:
but then the error pops in:
(related line is : node = kwargs)
What I'm doing wrong ?
bellow screnshots of what I'v done.
def mySuperFunction():
print("Test!");
node = kwargs['node']
parm = node.parm('spine_snake_lr').getReferencedParm()
parm.set(0.0)
and the expresion looks like this:
hou.pwd().hm().mySuperFunction();
return 0;
Error: Unable to evaluate expression (
Traceback (most recent call last):
File "<stdin>", line 2, in expression
File "opdef:/Object/tiger_rig_anim?PythonModule", line 3, in mySuperFunction
KeyError: ('node',)
(/obj/tiger_rig_anim1/reset)).
What I'm doing wrong ?
bellow screnshots of what I'v done.
- zengchen
- Member
- 77 posts
- Joined: 2月 2017
- Offline
-
- Quick Links