Page 1 of 1

how to handle multiple containers

PostPosted: Wed Apr 17, 2019 1:40 am
by dus
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!

Re: how to handle multiple containers

PostPosted: Wed Apr 17, 2019 6:04 pm
by Ivan
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()

Re: how to handle multiple containers

PostPosted: Thu Apr 18, 2019 10:18 am
by rob
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.

Re: how to handle multiple containers

PostPosted: Thu Apr 18, 2019 10:28 am
by hmbemba
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 = ......

Re: how to handle multiple containers

PostPosted: Thu Apr 18, 2019 5:44 pm
by nettoyeur
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

Re: how to handle multiple containers

PostPosted: Sun Apr 21, 2019 10:17 pm
by dus
thanks a lot for your answers, ill try them.
And the tag thing its awesome, i didnt know that exist, thank you!