Jump to content
Sign in to follow this  
Houdini7

For Each Element in Group

Recommended Posts

Hello,

yesterday i learned the very usefull For each SOP. As I understand an attribute is used and for every unique value of the attribute the for each body is called once. Now what I want to do is that the for each loop iterates through each element of a group (e.g. points). The iteration through all points is possible but not for points which are in a specific group. How can one achieve that in a simple way? Thanks in advance for your help.

Edited by Houdini7

Share this post


Link to post
Share on other sites

No one an idea ? I want to loop through elements of a group and execute my sops on that element. How can I achieve that ? With For each loop it seems it is not possible.

Edited by Houdini7

Share this post


Link to post
Share on other sites

You can use groups as a base for the Name SOP - creating a name attribute you can use as identifier for a piece in the for each loop.

 

Share this post


Link to post
Share on other sites
1 hour ago, pusat said:

Enumerate SOP can do this.

Thanks for this advice. Unfortunately the Enum SOP does nothing but enumerates the elements of the group, and every element not in group gets a -1 for the enumerate attribute. But the for each loop goes nonetheless over all elements. Even when the attribute is -1. Do I miss something ? I need the for each loop only go through the elements of a group.

Share this post


Link to post
Share on other sites
21 minutes ago, Hamp said:

You can use groups as a base for the Name SOP - creating a name attribute you can use as identifier for a piece in the for each loop.

 

Hi, thanks. Yes, thats another possibility. But the for each loop will loop through all elements, it does not constraint on the elements contained in a group.

Share this post


Link to post
Share on other sites

Hmm ... what do you mean by "element" in this scenario?

What are you , more concrete trying to achieve ? What's the end goal?

Edited by Hamp

Share this post


Link to post
Share on other sites
1 minute ago, Hamp said:

Hmm ... what do you mean by "element" in this scenario?

Element means a point or a prim which is in a group.

Share this post


Link to post
Share on other sites

Group -> Name -> For Each Loop -> Primitive SOP/VOP manipulation of points and prims is what I'm thinking , but hard to know without more info. Maybe I'm misunderstanding your question?

Share this post


Link to post
Share on other sites

An example for this scenario: I have a group with 3 points. I want to bevel this 3 points. So I want to use a for each loop which has the group as input and which iterates through every point (3 in this example) and executes the bevel SOP (body of the for each loop) on each point. I hope this is clearer now.

 

Remark: Yes, I know one can take the points directly in the group attribute of the bevel SOP (but you cannot take a group with points there, the old bevel SOP had this ability).

Share this post


Link to post
Share on other sites
4 minutes ago, Hamp said:

Group -> Name -> For Each Loop -> Primitive SOP/VOP manipulation of points and prims is what I'm thinking , but hard to know without more info. Maybe I'm misunderstanding your question?

Yes, but the for each loop goes through all primitives (points). You cannot exclude points, say you want to process all points in a group, how do you do this ?

Share this post


Link to post
Share on other sites
8 minutes ago, Houdini7 said:

An example for this scenario: I have a group with 3 points. I want to bevel this 3 points. So I want to use a for each loop which has the group as input and which iterates through every point (3 in this example) and executes the bevel SOP (body of the for each loop) on each point. I hope this is clearer now.

 

Remark: Yes, I know one can take the points directly in the group attribute of the bevel SOP (but you cannot take a group with points there, the old bevel SOP had this ability).

I haven't had time to look at the loop approach, but I managed to get a group of points to get beveled in the new bevel SOP.

Attaching file - is this what you want to do?

polybevel_pointGroup.hiplc

Share this post


Link to post
Share on other sites
28 minutes ago, Houdini7 said:

Thanks for this advice. Unfortunately the Enum SOP does nothing but enumerates the elements of the group, and every element not in group gets a -1 for the enumerate attribute. But the for each loop goes nonetheless over all elements. Even when the attribute is -1. Do I miss something ? I need the for each loop only go through the elements of a group.

If you loop over the enum attribute, the -1 will only be 1 iteration and you can skip it by using a switch node so it's not costly to do so.

Share this post


Link to post
Share on other sites
4 minutes ago, Hamp said:

I haven't had time to look at the loop approach, but I managed to get a group of points to get beveled in the new bevel SOP.

Attaching file - is this what you want to do?

polybevel_pointGroup.hiplc

Ah yes, that was what i tried. I think you entered the name of the group manually, because a point group is not displayed in the selector of the group attribute in the bevel sop. Good to know, thanks ! Nevertheless would be nice to know how one can iterate through group elements in a for each loop.

Share this post


Link to post
Share on other sites
11 minutes ago, pusat said:

If you loop over the enum attribute, the -1 will only be 1 iteration and you can skip it by using a switch node so it's not costly to do so.

Correct. The switch SOP is a nice idea, have searched for "if", but did not find anything ;-) So the idea is to set the "select input" of the switch SOP to the bevel SOP if the enum attribute is unequal 1 and to the "for each begin" SOP if it is -1 (effectivly skipping the bevel SOP). For this, one needs the expression for the "select input", how can I access the current enum attribute in the for each body, do you know this ? Perhaps you have an idea how the expression must look like, or there is another better way without expressions. Thank you.

Share this post


Link to post
Share on other sites
1 hour ago, pusat said:

If you loop over the enum attribute, the -1 will only be 1 iteration and you can skip it by using a switch node so it's not costly to do so.

Okay, I have found the solution. The switch SOP must use the following expression: prim(opinputpath(".",0),0,"index",0) < 0 for the select input. It uses the index attribute of the input 0 and compares it to 0.

Share this post


Link to post
Share on other sites

Hey! Happy it worked out :)

Care to share the .hip setup of the loop version? 

Edited by Hamp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×