Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

how to handle multiple containers

Still a little green? Ask your beginner's questions here

how to handle multiple containers

Postby dus » Wed Apr 17, 2019 1:40 am

hello!
i was wondering if there is a way to tell touchdesigner in phyton to go from a list of operators and do the same thing by their number or by name, for example if i have 20 operators called: null1, null2, null3, etc to null20, how could i say that when all of those operators are in 0 do something, is there a way? should i convert that data to a table, or should i do variables or is there something like range(19) in phtyon? ive thinking about this for days but i pretty far from solving it

thanks for the help!
dus
 
Posts: 12
Joined: Tue Jun 19, 2018 6:44 pm

Re: how to handle multiple containers

Postby Ivan » Wed Apr 17, 2019 6:04 pm

Your question isn't totally clear, but if I understand, you might want something like this:

Code: Select all
for compNum in range(20):
   comp = op('null' + str(compNum))
   comp.DoSomething()
User avatar
Ivan
Staff
 
Posts: 235
Joined: Fri Mar 18, 2016 7:12 pm

Re: how to handle multiple containers

Postby rob » Thu Apr 18, 2019 10:18 am

Depending on the naming convention, you can also use the ops function to get them directly:

Code: Select all
for comp in ops('null*'):


or

Code: Select all
for comp in ops('null[1-20]'):


etc.
User avatar
rob
Staff
 
Posts: 1667
Joined: Tue Nov 13, 2007 1:14 am

Re: how to handle multiple containers

Postby hmbemba » Thu Apr 18, 2019 10:28 am

Here's some code I like to use often in a textdat

Code: Select all
path = me.parent().findChildren(type=TOP, depth=1)
for x in range( len( path ) ):   
         #If you want to skip certain ops
   #if path[x] != ' ' : #and path[x].base != ' ':
      #Print these ops
      print(path[x])
      # op(str(path[x])).par.whatever = ......
hmbemba
 
Posts: 32
Joined: Mon Mar 27, 2017 6:48 pm

Re: how to handle multiple containers

Postby nettoyeur » Thu Apr 18, 2019 5:44 pm

Also checkout Tags: https://docs.derivative.ca/Tag

You can give any operator one or multiple tags. Together with the findChildren method this is a very powerful and fast way to find a group of nodes and do something with them.

The findChildren method is explained here:
https://docs.derivative.ca/COMP_Class#Methods
Idzard Kwadijk | freelance TouchDesigner consultant | IdzArd.com
Checkout ChopChopChop.org - the TouchDesigner marketplace!
nettoyeur
 
Posts: 1140
Joined: Mon Oct 15, 2012 12:00 pm
Location: Amsterdam, The Netherlands

Re: how to handle multiple containers

Postby dus » Sun Apr 21, 2019 10:17 pm

thanks a lot for your answers, ill try them.
And the tag thing its awesome, i didnt know that exist, thank you!
dus
 
Posts: 12
Joined: Tue Jun 19, 2018 6:44 pm


Return to Beginners

Who is online

Users browsing this forum: Google [Bot] and 20 guests