Expressions python scripting

   1978   5   1
User Avatar
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.

Attachments:
Screenshot_2.png (46.1 KB)

User Avatar
Member
8551 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:
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)
or
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
User Avatar
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 this
node = kwargs['node'];parm = node.parm('snake_lr').getReferencedParm();parm.set(0.0)
or
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 :/)

Attachments:
Screenshot_1.png (42.0 KB)

User Avatar
Member
8551 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]
Edited by tamte - 2020年3月25日 18:20:39
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2 posts
Joined: 3月 2020
Offline
I'm still strugling with it, as You mentioned I'v created callback function:
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;
but then the error pops in:
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)).
(related line is : node = kwargs)

What I'm doing wrong ?
bellow screnshots of what I'v done.

Attachments:
Screenshot_1.png (62.4 KB)
Screenshot_2.png (32.9 KB)

User Avatar
Member
77 posts
Joined: 2月 2017
Offline
You must put the kwargs as parm to callback func

hou.pwd().hm().mySuperFunction(kwargs)
Edited by zengchen - 2020年3月29日 07:41:13

Attachments:
test.gif (452.8 KB)

My Youtube Channel [www.youtube.com]
  • Quick Links