CGTalk > Software > Maxon Cinema 4D
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-14-2013, 10:57 PM   #1
fusepilot
Veteran
portfolio
Michael Delaney
Minneapolis, USA
 
Join Date: Aug 2008
Posts: 38
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)
 
Old 04-14-2013, 11:26 PM   #2
fusepilot
Veteran
portfolio
Michael Delaney
Minneapolis, USA
 
Join Date: Aug 2008
Posts: 38
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.
 
Old 04-15-2013, 08:07 AM   #3
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
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.
 
Old 04-15-2013, 05:40 PM   #4
fusepilot
Veteran
portfolio
Michael Delaney
Minneapolis, USA
 
Join Date: Aug 2008
Posts: 38
Quote:
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.

Quote:
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.

Code:
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)
 
Old 04-15-2013, 07:58 PM   #5
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
Quote:
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:

Code:
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.

Code:
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

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

Last edited by littledevil : 04-15-2013 at 08:21 PM.
 
Old 04-15-2013, 10:49 PM   #6
Darter
Positive buoyancy
 
Darter's Avatar
David Wickenden
Ballina, Australia
 
Join Date: Nov 2003
Posts: 1,227
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.
 
Old 04-15-2013, 10:49 PM   #7
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:44 AM.


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