Xpresso Texture Tag Loop Problem

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  04 April 2013
Xpresso Texture Tag Loop Problem

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.
Attached Files
File Type: zip tag_texture_loop.c4d.zip (107.3 KB, 4 views)
 
  04 April 2013
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.
 
  04 April 2013
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.
 
  04 April 2013
Originally Posted by littledevil: 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

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.

Originally Posted by littledevil: everything else is programmatically not possible.

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?
Attached Files
File Type: zip tag_texture_loop_2.c4d.zip (115.9 KB, 6 views)
 
  04 April 2013
Originally Posted by fusepilot: Definitely not impossible. Here's a Python Tag I wrote that does what I wanted.


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).



2. use a common index like in your example

for commonindex in xrange(a,b):
   n = list0[commonindex]
   m = list1[commonindex]
   yield n + m

Last edited by littledevil : 04 April 2013 at 08:21 PM.
 
  04 April 2013
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.
 
  04 April 2013
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:48 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.