For each Group: What am I doing wrong?

   19682   17   4
User Avatar
Member
856 posts
Joined: Oct. 2008
Online
I want to assign a random attribute value to each group, say a color value.

So, I break geometry and get many piece groups.

In ForEach SOP I set Group Mask to piece*

Inside the Foreach SOP I append a color node to the each1 node. In that color node I type: rand(stamp(“../”,“FORVALUE”,0))

but all my pieces have the same color. Where am I going wrong?
--
Jobless
User Avatar
Member
696 posts
Joined: March 2006
Offline
you are attempting to get a random number based on a string…

float rand(float stamp(string forvalue)))

This needs to be done another way… you somehow need to get your forvalue to translate into a number.
Stephen Tucker
VFXTD
User Avatar
Member
1631 posts
Joined: July 2005
Offline
Perhaps you can use opdigits() around the stamp() function to get the number of the group name and pass that to rand().

Cheers!
steven
User Avatar
Member
856 posts
Joined: Oct. 2008
Online
Oh, how silly of me. I assumed it was just a counter.

Is there a counter or something like that? I checked the docs but there seem to be no local attributes. Or a group number?
--
Jobless
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
You could add a detail attribute to the SOP Tree when you are using attribute or group options. No need to use it in the counter method.

Initialize say i ($I) to 0 then do an $I+1 in an Attribute Create SOP. Each iteration will increment your detail attribute.


fyi, detail attributes ride on top of the geometry and you can only have a single entry per attribute. They tend to be very light though.
There's at least one school like the old school!
User Avatar
Member
856 posts
Joined: Oct. 2008
Online
I tried the detail attribute but I'm still doing something wrong… I can't figure it out…

Has it go to do with the detail attributes being assigned to every group or once to the whole geometry?

In the appended file I tried to delete every other group.

Attachments:
groupit.hipnc (113.2 KB)

--
Jobless
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
First off that first group “inside0” was messing things up a bit so best to use the Group Mask piece* to only process the pieces you want.


The i detail attribute incrementor technique works when you toggle off merge results which makes sense. By not merging the results, you are passing the resulting geometry back through the SOP network and then the $I is incremented and kept. If merge results is off, then the input geometry is sampled fresh for each iteration.

So…

You can use the opdigits() expression on the group parameter reference in to the Each SOP. That will extract the trailing digit which should do what you want while keeping the merge results toggle on.

See the example file for both techniques where I used message (yes it gets annoying real fast) to visualize how the various techniques increment.
Surprising to see that the groups are not processed in order…

Attachments:
groupit_169_v02.hipnc (166.4 KB)

There's at least one school like the old school!
User Avatar
Member
665 posts
Joined: July 2005
Offline
Hi Sooth,


In regards to the first question. Have a look here.

http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=16047&highlight= [sidefx.com]

cheers,
-j
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
Nice custom hscript expression Jacob. Yeah use Jacob's method if your groups are not numbered sequentially.

As far as groups being processed randomly anyway, it really doesn't matter in many cases as long as you have a random number generated. Statistically speaking rand() should give you a 50% probability of being above 0.5 and below 0.5.

Ultimately it still would be nice to have your groups sequentially numbered. Bad Maya modelers, bad. lol
There's at least one school like the old school!
User Avatar
Member
856 posts
Joined: Oct. 2008
Online
Jeff, you did something mysterious there I can't fathom with my sleepy brain. In the “each” node there is an expression:

ifs(!!strcmp(chs(“../fortype”), “group”), “”, stamps(“..”, chs(“../forstamp”), “”))

What does it do? Where is that node called “fortype” and “forstamp”?
--
Jobless
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
That expression is added to the Each SOP by default when you first place the Foreach SOP.

This expression simply returns the current group being processed as a string.

The first strcmp is used to see if you are using the group option, the second part returns the group name for you.

fortype and forstamp are actually the parameter names on the top ForEach SOP. ../ means go up one directory (which is the ForEach SOP) then fetch the parameter values from fortype and forstamp.

If I want to use the group name specifically, I just RMB on this parm and copy the parm then past relative reference and voila, you get the current group name being processed. I see many users copying the literal expression. No need to that. Just a chs() channel reference to this parm gets you the group name.
There's at least one school like the old school!
User Avatar
Member
84 posts
Joined: July 2013
Offline
hey,

some years later. Helpful thread. But I have propblem accessing details attribute from last iteration..to sum up my detail attrib at end.
the foreach is driven by attribute value.
for each example(last row is what i want):

iteration detailattrib result (sum every iteration)
1 ————> 5 ———> 5
2. ———–> 3 ———> 8
3. ———–> 2 ———–> 10
4. ———–> 4 ———–>14
..

My idea: sum=sum(current iteration)+sum(last iteration)
BUT I can't using “MERGE RESULTS” !!

any advice would be great!.

thanks, tom.
User Avatar
Member
8532 posts
Joined: July 2007
Offline
do you need to use merge results?

if you don't check that, you can still isolate current iteration geo and merge to all previous ones from feedback geo and sum your detail so in the end you will end up with merged results and summed detail or whatever
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
84 posts
Joined: July 2013
Offline
hey tamte,

big thanks for trying to help
First my fail: I need to CHECK “merge results”, of course.

Since I am working on a tree generator, the most stuff is happening inside the foreach stuff. If I useing feedback-loop, everything is exploding ;(

So I don't have something like a feedback, its only merge every iteration at the end of sops level (like jeff explained above).
I can't look back to my last iteration like stamp(“..”,“FORVALUE”,0) - 1

So I have rebuild my problem i a reayl simple scene, which I have attached.
I tried a lot the last 2 day…but now my brain is bending


thx. tom

Attachments:
foreach_accum_attrib.hiplc (95.3 KB)

User Avatar
Member
8532 posts
Joined: July 2007
Offline
I meant that you can replicate Merge Results by merging geometry to fed-back one, but with the advantage of appending every iteration therefore summing up attribs or anything
I'll have a look at it at home, not being able to upload from work
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
84 posts
Joined: July 2013
Offline
tamte, thanks for taking time and replying so fast. Especially from you

i could feel what you mean…to recreate the “merge results” inside a feedback loop. But it seems to be a big change for tiny little problem.

Like I mentioned before its for a treegenerator. Every branch generation I want to happen in a linear fashion, not inside a feedback loop. So one node for every generation to get the unique controll(distribution, shaping) for every iteration/generation.
User Avatar
Member
8532 posts
Joined: July 2007
Offline
don't worry, it's simple enough
here are 2 methods

1. foreach in feedback mode, processing each iteration the same way as if merge results was on (just geo of the same attrib value), then adding it to accumulated geo from previous iterations and summing the attrib or whatever

2. foreach in merge results mode, but creating additional point per iteration holding your desired data
after foreach splitting the geo and data points, accumulating value of data points as geo detail attrib

Attachments:
ts_foreach_accum_attrib_2_methods.hiplc (145.6 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
84 posts
Joined: July 2013
Offline
Big thanks for your solutions !!

I think I have to use your Method 1. Because I have to access the accumulation result every iteration step inside the foreach.
Now my understanding of foreach become better and better …now it look like a sopsolver. But not time depend, whats great in my case.

THANKS
  • Quick Links