Jump to content

For Each Element in Group


Houdini7

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
Link to comment
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.

Link to comment
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.

Link to comment
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).

Link to comment
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 ?

Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...