Creative Programming

There are  numerous ways to link and control parameters in TouchDesigner; references, bindings, exports. We can also use Replicator COMPs or Clones when we want to have a master COMP controlling a number of other COMPs. By reading this post you will learn a different way of controlling parameters in TD!

The trick here is to find a way to have a master operator (in this example a Container COMP) to control all other desired same type operators in your project (here, Container COMPs). This technique is a 2-way technique; one to find which COMPs you want to change, and the other one the code to implement for controlling. Let's start by simply create a Container COMP called container1, and two other Container COMPs called container1 and container2. We want to control container2 and container3 from container1.

The first task is to detect the path of the container2 and container3. For this task we will use the Opfind DAT, an extremely useful tool for finding operators in all your project. Let's create the Opfind DAT and set the exported information to be Name and Path.

There are plenty of ways to find operators with Opfind DAT and you can see these ways in the Filter page. In this example, we are going to use tags. We are going to tag the containers with the same tag, in order them to be visible when the Opfind DAT scans the network. Let's give the tag myTag to the two Container COMPs.

Now, we can go to the Opfind DAT and write the myTag to the FIlter page.

As you can see, the Opfind automatically detected the two Container COMPs, and output the name and the path. Of course, if your COMPs are on other levels of your network you can set the scan to start on a different level by change the parameters in the Component page.

Now let's move on to second task which is the way to control the containers. The logic here is: when I move a parameter on the primary COMP, the same parameter will be controlled on all other COMPs. Let's add a Parameter Execute DAT and set the OPs parameter to be container1 and to look on all parameters.

It's time for some python!

In the code above we scan the Opfind DAT line by line and we get the path of the target Container COMPs. Then with this information we use the setattr function which requires a little explanation. The setattr function is used when we have the name of a parameter as a string and we want to access this parameter. For example, the line of code setattr(op('level1').par, 'opacity', 0.5) will write the value 0.5 to the opacity parameter of the level1 operator. Having this in mind, in our code we set with the first argument the operator destination (that we found with the Opfind DAT), with the second argument the name of the parameter (which is the same as the one that we move on the container1), and with the third argument the value of the parameter. That's it!


In the example above, we used Container COMPs for demonstrating the trick, but you can use this trick with any operators in TouchDesigner. Hopefully, by reading this post, you have gained one more technique for parameter control!

Written By
Vassilis Malamas