Execute Python code only if parameter is changed

   1957   1   1
User Avatar
Member
7 posts
Joined: Dec. 2017
Offline
I need to execute Python code only if certain parameter is changed

def func():
    print 'Hello World!'
"""
pseudocode:
if ch('../null1/tx') changed:
    func()
"""
Edited by Garry_cg - Aug. 29, 2018 08:27:53

Attachments:
execute_py.hipnc (58.8 KB)

User Avatar
Member
2625 posts
Joined: June 2008
Offline
It is kind of a two-step process. You have to specify a callback for the parameter you want to monitor. The callback script defaults to the Hscript language so you have to remember to click the H icon and change it to the Python icon or this code will not work.
exec(hou.node("/obj/pythonscript1").parm('python').eval());MyFunction("/obj/CHANGE_PARAMETER_HERE","my_parm")
So you define a call to your function and can even pass along hard coded constant variables. You don't get the value of your parameter in the call back, only the reference to where you can find the value.

In your python script use something like this to get the value.
def MyFunction(passedNodeName, passedParmName):
    print "Node [%s] called me." % passedNodeName
    n = hou.node(passedNodeName)
    if n != None:
        p = n.parm(passedParmName)
        if p != None:
            print "With a value of [%s]." % p.eval()
Edited by Enivob - Aug. 29, 2018 15:27:10

Attachments:
ap_execute_py.hipnc (66.4 KB)

Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
  • Quick Links