Jump to content

attach python code to parameter change event


Recommended Posts

I've a hip file with a dop which doesn't recook as it should when I change certain node parameters upstream.

In order to make it work I need to bypass on and off the dop network manually,

OR perform in a Python shell:

hou.node('/obj/dop_version/dopnet1').cook(True)

Is there a way I can attach this Python code to the a parameter in a node, so that when I change the parameter content, the code gets executed ?

Alessandro

Link to comment
Share on other sites

Thank you Jagadeesh !

I tried that and it works.

But it works only if I change the content of the parameter manually, via UI.

If I , for instance, keyframe that channel, the callback script is not executed at play time.

Is there a way to have the callback script executed every time that parameter changes , regardless how, OR to have a callback script run whenever a certain node is cook ?

You can attach this to any parameters callback script. Properties -> Parameter Description -> Callback Script. Change the language from Hscript to Python. Callback script runs whenever the parameter value changes. I hope this helps

Cheers

-J

Link to comment
Share on other sites

Jagadeesh,

this is really handy node, thank you for the hint !

It doesn't fix my issue cause even if i force the cook of a dop network , for some reason it works only if i change that parameter manually, not in 'play' mode, but it's a really handy sop node and a huge help do debug issues.

Link to comment
Share on other sites

Alessandro,

You can make the Script sop time dependent. Make sure you check the Make Time dependent Toggle. This will make sure that the Script runs every frame. Now you can directly call the cook function in the Script. Or if you want this to be tied to a parameter callback, then a nice little trick would be to have a button parameter with the callback script. Then in the Script sop you can do something like hou.node("../blah").parm('buttonParm').pressButton(). This will press the button every frame and the callback script gets executed every frame. Hope this helps :)

Cheers

-J

Edited by jagadeesh
Link to comment
Share on other sites

hey Jagadeesh this is a really neat trick.

I'll definitely use it sometimes.

It turns out the problem I was having was caused by an incorrect use of dops and sop solvers.

This is where I explain the issue.

Alessandro,

You can make the Script sop time dependent. Make sure you check the Make Time dependent Toggle. This will make sure that the Script runs every frame. Now you can directly call the cook function in the Script. Or if you want this to be tied to a parameter callback, then a nice little trick would be to have a button parameter with the callback script. Then in the Script sop you can do something like hou.node("../blah").parm('buttonParm').pressButton(). This will press the button every frame and the callback script gets executed every frame. Hope this helps :)

Cheers

-J

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