How to Synchronize Constant Values Between Two Chop Ops in TouchDesigner Using Python?

I want to make it so that when the constant value of one chop op increases or decreases, the constant value of another chop op changes accordingly. I tried using the Python code of the data op for this, but simply incrementing the constant value doesn’t make the target chop op’s constant value change. Do you have any ideas to solve this?

Hi, think you just need to delete the if clause and it should work.

Alternatively you could just enter the following expression into the constant value0 Parameter itself:

op('null1')['handDistance']

You could achieve the same result by hitting the ‘a’ key when you select the null1 chop and drag the channel to the desired parameter you want to change.

I hope this does what you hope for☺️

Hi @tg50231,

if they have the same value, you could also just use a bunch of Rename CHOPs or Select CHOPs to branch out…

cheers
Markus

I am currently working on a project in TouchDesigner and would like to execute a Python script whenever a specific CHOP value (e.g., a “handDistance” Constant CHOP) increases or decreases.

I have already learned how to trigger code execution using the Count CHOP, but I would like to understand how to execute a script automatically when a particular CHOP value changes, without relying on a manual trigger like Count CHOP.

Since I am still in the process of learning programming, I would really appreciate a clear explanation or example on how to achieve this in Python within TouchDesigner.

Hi @tg50231,

can you further describe what your goal is? Mainly asking because you are doing the right thing by using a CHOP Execute DAT and utilizing the onValueChange callback.

Now it’s difficult to debug with screenshots. Makes it tedious and time intensive to try to see what’s going on. Hence it’s always nice to post a Minimal, Reproducible Example - especially when dealing with code.

Now looking further into your screenshot, I can see that you have 3 operators called x, y, and z. In the callback function you are referencing three operators but here you are looking for op('X'), op('Y'), and op('Z') - with TouchDesigner and python being strongly case-sensitive the op() function will return the value None and with your if condition checking against it, the execution of the code does not proceed.

Written out it is like this:

x_op = op('x')
# since there is no operator called "x" the variable x_op will be None
debug(x_op)

# with the variable x_op having now the value None, this condition results in False and the indented code will not be executed
if x_op:
    x_op.par.value0 = val

Some things to watch out for:
With the introduction of sequential parameters, the Constant CHOPs parameter names have changed. While previously you could reference the value part with value0, this has now changed to the sequential parameter notation of const0value.

For a good introduction into TouchDesigner and python, have a look at our curriculum at
learn.derivative.ca

cheers
Markus