Python Script outputs from Text DAT to Transform TOP

Hello everyone!

I’m very new to Touch Designer and python so apologies if the answer is very simple!

I want to a put a small piece of python code (seen below) in to a text node, and transfer the output of this script to a Transform node (to translate ty).

The python code I want to use is:

from time import sleep

run = True
delay = 5

while run:
	var = -0.25
	for i in range(20):
		if var < 0.7:
			var += 0.05
		else: run = False

I want the printed ‘var’ value (which should change every five seconds) to affect the translate ty variable of the transform TOP (see image below), therefore affecting the main scene over time.

I don’t think the code is written in the right way to output the ‘var’ value as it changes, rather than printing it, but unsure of how to do this. I think I may also have to import the ‘sleep’ module in to touchdesigner?

Any pointers on how I might be able to achieve this would be amazing!

Thanks! :slight_smile:

So if you’re trying to access a parameter and assign it a value or use it in your Python code, you need to use the syntax:


There are some differences, like if you’re using CHOPs at all, you’re going to be using the same front half of the code, but changing it to:


Also yes, if you’re trying to use a library/module that isn’t in vanilla Python, you do typically need to import it as you say.

Hope that this clarifies and helps!

1 Like

Hi Luxnaut,

That’s really helpful. Thanks so much!

1 Like

P.S. Also, use the evaluate DAT if you’re ever curious what your expression is actually giving you

Just a note but your code will not work as you expect it to. It will simply freeze touchdesigner until the condition is no longer met.
I assume you come from processing or similiar?

Get a grasp of differrent chops and check some tutorials because this approach is complelty wrong in a way that touchdesigner uses another paradigm.

This comment is entirely unhelpful and derogatory. You could link some tutorials or explain the programming paradigm of touchdesinger if you were really trying to be helpful.