Hi Guys,
I’m playing since four with TD around and learnd a lot so far.
But now I ran into a problem I can’t solve by my own or with friends.
I want to toggle a Button via Chop on value change.
To be more exact: I want to execute the rotate Buttons (left or right) of the Kantan Mapper with the Chop thats matched a calculated rpm of a stepper motor.
So far a friend send me an answer from Chat GPT:
In TouchDesigner, triggering a button COMP using a CHOP is definitely possible, and there are a few ways to accomplish it depending on the exact behavior you want to trigger and how your network is set up. Here is a general approach you can take:
Select CHOP: Use a Select CHOP to isolate the channel from your CHOP network that you want to use to trigger the button. The channel should ideally be a toggle or a pulse that goes from 0 to 1 when you want the button to be “pressed”.
CHOP Execute DAT: You’ll need to use a CHOP Execute DAT that monitors the channel coming from your Select CHOP. Inside the CHOP Execute DAT, you can write a script in Python that will be executed whenever the channel value changes.
Python Scripting: Within the CHOP Execute DAT, you can write a Python script that triggers the button COMP. For example, if you want to trigger the button when the channel value goes from 0 to 1, you could use something like this:
def valueChange(channel, sampleIndex, val, prev):
# val is the new value of the channel
# prev is the previous value of the channel
if val == 1 and prev == 0:
# Fetch the Button COMP
button = op('path_to_button_comp')
# Simulate button press
button.click()
return
Implementing the Script: You would replace ‘path_to_button_comp’ with the actual path to your button COMP. The .click() method simulates a button click.
DAT to CHOP: If the button COMP is linked to a value in a DAT, such as a table DAT or script DAT, and that value is what actually triggers the rotation, you might need to write to this DAT instead of triggering the button COMP directly. This is usually done via the .run() method on the DAT or by modifying its .text or .par.value properties, depending on how the Kantan Mapper listens to button presses.
Monitoring Frequencies: If you want the button to trigger at the frequency of a CHOP, you would need to ensure the CHOP you’re using to trigger the button changes value at the frequency you desire.
Sounds like it could work, but I dont get it to work.
Can somebody help with that?