My name is ibuibu69 and I make videos and music as a hobby! I used to do things like VJ and instrumental bands using max and processing. .. https://www.youtube.com/watch?v=NswI72i6lCg
... The band has disbanded and I want to do something new with Touch Designer these days. I live in Tokyo, so please make friends with me. ..
Now, let's post the first Advent calendar.
When trying to do difficult things with TouchDesigner, control by python becomes indispensable.
However, I think there are relatively few TouchDesigner users (including myself) who are familiar with python. .. .. maybe. ..
Therefore, here are some tips for batch operations of operators using for statements, which you will often use.
For example, "Substitute 1 for value 0 of constant 1, 2 ... 9" is as follows.
for i in range(1,10):
op( 'constant' + str(i) ).par.value0 = 1
This is easy, isn't it?
Commentary: Since the inside of op () is a string, i must be a string with str ().
For example, "Substitute 1 for values 1, 2, ... 9 of constant1" is as follows.
for i in range(1,10):
script = 'op(\'constant1\').par.value' + str(i) + ' = 1'
exec(script)
print(a)
Use the exec function. (I didn't know this and struggled.)
Tips: To make the value item number an iterator, first write the entire statement you want to execute in string type and embed the iterator. Then execute it with the exec () function. Don't forget to escape the quotes! !!
For example, "Display the total value of 1,2, ... 10 of constant1" is as follows.
a = 0
for i in range(10):
a += eval('op(\'constant1\').par.value' + str(i) )
print(a)
It's similar to the exec function above, but this time it uses eval, a function that evaluates values.
You may use the exec function as shown below.
a = 0
for i in range(10):
script = 'a += op(\'constant1\').par.value' + str(i)
exec(script)
In this way, when you want to turn TouchDesigner's built-in function with a for statement, using exec or eval works well.
It was an introduction! !!
I occasionally upload videos and music on twitter. I would be grateful if you could follow me.
https://twitter.com/ibuibu69
Recommended Posts