Xpresso Texture Tag Loop Problem


#1

I’m trying to loop through all texture tags on a parent object and apply its respective material to its children’s texture tag. It currently works when there is only 1 texture tag on the parent object, any more and the breaks. The print to console node however shows that each material is being found.

Any ideas, or is this a bug? Scene is attached.

Thanks.


#2

I just figured out how to do something similar with an link list node. I would still like to know why this approach doesn’t work.


#3

you were trying to mix two iterators and also your hierarchy node has a depth of zero.
if you want to mix to iteration operators you have either use a shared loop index for both
or nest one iteration within the other, which would be an xgroup in xpresso. everything else
is programmatically not possible.

edit : the hierarchy node and the tag node are the two iterators.


#4

I’m not sure how this would look in Xpresso. And it doesn’t explain why it works when theres one texture tag attached to the parent. And why the print to console node prints all of the texture tags I wanted to grab. It should just apply the last texture tag found.

Definitely not impossible. Here’s a Python Tag I wrote that does what I wanted.

import c4d

def main():
    parent = op.GetObject()
    parent_tags = parent.GetTags()
    parent_children = parent.GetChildren()
    parent_materials = []
    
    for tag in parent_tags:
       if isinstance(tag, c4d.TextureTag):
           mat = tag.GetMaterial()
           parent_materials.append(mat)
           
    for index, child in enumerate(parent_children):
        child_tags = child.GetTags()
        
        for tag in child_tags:
           if isinstance(tag, c4d.TextureTag):
               tag.SetMaterial(parent_materials[index % 3])

How do you translate this into Xpresso?


#5

you did exactly what i described. you used a common index for both loops (you just
took the extra step to store the result of the first loop in a list). what you were trying
in xpresso is logically impossible. you did more or less this:

for A in list0:
   r0 = A
for B in list1:
   r1 = B
x = r0 +  r1

both loops run indepently and therefore cannot access the others loop iteration steps.
the given example would just add the last member of both lists.

you have to understand that the tagnode can behave like an iterator. it does work
like baseobject.gettags(), it returns a list of tags matching your filter. when you have
only one texture tag it does not work as an iterator anymore and just returns one tag.
i described both possible solutions in my first posting, not sure how i could be more clear
about this.

  1. nested loops -> xgroup, feed xgroup with the result of an iterator.
for n in foo:
   for m in bar:
      yield n + m

edit : here an example, note that the xgroup is actually not necessary, but it helps a lot
to keep the parts separated so that you do not mix up the different loops (which will
fail the parsing of your graphview tree).

  1. use a common index like in your example
for commonindex in xrange(a,b):
   n = list0[commonindex]
   m = list1[commonindex]
   yield n + m

#6

The expression works as expected if you directly connect the Hierarchy and Tag node Object ports.

I’m not sure why the Object Index node is causing an error. XGroup node order doesn’t appear to be the problem in this case.


#7

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.