Foreach Iteration Value

   18821   5   1
User Avatar
Member
665 posts
Joined: July 2005
Offline
I am stumbling through the ForEach SOP at the moment, and am trying to find a way to hack together the Iteration Value.

Using the Group Field Seems to be pretty efficient, but I am curious as to whether i is available. Or do I have to use Range for this scenario?


cheers,
-j
User Avatar
Member
4343 posts
Joined: July 2005
Offline
You should be able to set the ‘fortype’ to Number Range. Then you fetch your ‘i’ value with stamp(“..”,“FORVALUE”,0)
if(coffees<2,round(float),float)
User Avatar
Member
1533 posts
Joined: July 2005
Offline
you could look at creating a ‘serial’ integer attribute on each group (much like the connectivity sop creates in it's “class” attribute), and then simply looking it up inside the foreach.


But I agree, having the iteration number available even when doing group-foreach'es would be <michael bay> AWESOME </michael bay>

G
User Avatar
Member
665 posts
Joined: July 2005
Offline
Hi Guys,

Having sweet group numbers I could extract would be great for this.

Unfortunately, the modelers weren't so kind. I ended creating an expression to return a random value based on a string input. It's not sequential, but seemed to numerically isolate each group pretty well.

Basically, I used the FORVALUE, a group name, to create a random seed.

See Below…

cheers,
-j



fxStringToRandFloat(string arg)
{
# create a index list of all the String Characters
string list = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_”;

len = strlen(arg);

val = 0;
string letter = “”;
string allLetters = “”;

# loop over all the characters in the provided string
for (i = 0; i < len; i++)
{
letter = substr(arg,i,1);
# find the value of the character and add to the total
val = rand(index(list,letter) + rand(i*i) + val);
}

# return a random value from the total string value
return rand(val + len);


}

User Avatar
Member
127 posts
Joined: July 2005
Offline
A bit late here but for anyone else searching for this. If your groups are numbered sequentially group1, group2, …, groupN then the following will get you there by stamping the group name and extracting the number all in one short line.

opdigits(stamps(“..”,“FORVALUE”,0))

I used it for example to drive a random selection on a switch node with three inputs like this:

floor(rand(opdigits(stamps(“..”,“FORVALUE”,0)))*3)

-Fabian
User Avatar
Member
23 posts
Joined: July 2015
Offline
maybe late but….
thanks Fabian!

your post was useful to me today
  • Quick Links