Question about unique names in loops for each.

   3792   3   4
User Avatar
Member
280 posts
Joined: 12月 2015
Offline
Hi everyone,
Anyone knows how to reach the iteration number in a for each loop to use it as a name in objects I create inside it?

Basically I am trying to give unique names to pieces from a voronoid fracture that runs multiple times inside a for each loop.
Like piece_Iteration01_01, piece_Iteration01_02 and next iteration (part processed) will be piece_Iteration02_01, piece_Iteration02_02 I hope I am making sense here.

I attached a simple hip file to focus on what I meant. As you can see all pieces out of the for each loop have same Piece0,piece1,piece2,piece4 name. I assume this is an issue with wathever we create in the for each loop. so there must be a way to add a unique id to each iteration right?

Any help will be greatly appreciated.
Nico.

Attachments:
name question.PNG (31.6 KB)
Foreachnamesquestion.hiplc (125.2 KB)

https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
8583 posts
Joined: 7月 2007
Offline
you need to create new Block Begin SOP in Metadata mode and point it to your foreach_end1, there you will find detail attribute called iteration
the easiest way to create it is to select your foreach_begin1 node and click on Create Meta Import Node button

then you can reference that detail attribute wherever you want, in case of example file in voronoifracture2/Attributes/NamePrefix

Attachments:
Foreachnamesquestion_fix.hiplc (125.9 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1743 posts
Joined: 5月 2006
Offline
one way: (doesn't answer your question directly in the way Tomas did, but avoids the detail referencing stuff that I still think is a little messy with for/each loops)


copy @name to @parentname before the loop, concatenate @parentname and @name inside the loop, delete @parentname after the loop.

Attachments:
Foreachnamesquestion_me.hiplc.hipnc (157.5 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
280 posts
Joined: 12月 2015
Offline
Thank you very much guys!

Both solutions are quite elegant.
The metadata node in order to retrieve the iteration number it is exactly what I was searching for.
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
  • Quick Links