In TouchDesigner, you can use a CHOP Execute DAT to monitor the values of your channels and set the index of a switch based on which channel has the highest value. Here’s a step-by-step guide on how to achieve this:
-
Create the CHOP Execute DAT:
- Right-click on your network, go to
DAT -> CHOP Execute DAT.
- Connect the CHOP you want to monitor (the one with ‘angel’, ‘hero’, ‘feminist’, ‘rebel’) to the
CHOP Execute DAT.
-
Configure the CHOP Execute DAT:
- In the
Parameters of the CHOP Execute DAT, set Execute to onValueChange.
- In the
Callback DAT, write the following script to set the index of the switch based on the highest channel value:
def valueChange(channel, sampleIndex, val, prev):
# Get the values of the channels
angel = op('your_CHOP_path')['angel'][0]
hero = op('your_CHOP_path')['hero'][0]
feminist = op('your_CHOP_path')['feminist'][0]
rebel = op('your_CHOP_path')['rebel'][0]
# Find the channel with the highest value
values = [angel, hero, feminist, rebel]
max_index = values.index(max(values))
# Set the index of the switch
op('your_switch_CHOP_path').par.index = max_index
Replace 'your_CHOP_path' with the actual path to your CHOP containing the channels ‘angel’, ‘hero’, ‘feminist’, ‘rebel’, and 'your_switch_CHOP_path' with the path to your switch CHOP.
-
Ensure Proper Channel Names:
- Make sure your CHOP channels are correctly named ‘angel’, ‘hero’, ‘feminist’, ‘rebel’. If they are not, you can rename them using a
Rename CHOP before connecting to the CHOP Execute DAT.
-
Test the Setup:
- Change the values of the channels and observe if the switch index changes accordingly to the highest value channel.
This script will execute every time there is a change in the values of any of the channels, ensuring the switch index is always set to the channel with the highest value.