Houdini7 Posted August 24, 2017 Share Posted August 24, 2017 (edited) 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 August 24, 2017 by Houdini7 Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 (edited) 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 August 24, 2017 by Houdini7 Quote Link to comment Share on other sites More sharing options...
animatrix Posted August 24, 2017 Share Posted August 24, 2017 Enumerate SOP can do this. Quote Link to comment Share on other sites More sharing options...
Hamp Posted August 24, 2017 Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Hamp Posted August 24, 2017 Share Posted August 24, 2017 (edited) Hmm ... what do you mean by "element" in this scenario? What are you , more concrete trying to achieve ? What's the end goal? Edited August 24, 2017 by Hamp Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Hamp Posted August 24, 2017 Share Posted August 24, 2017 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? Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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). Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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 ? Quote Link to comment Share on other sites More sharing options...
Hamp Posted August 24, 2017 Share Posted August 24, 2017 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 Quote Link to comment Share on other sites More sharing options...
animatrix Posted August 24, 2017 Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
Houdini7 Posted August 24, 2017 Author Share Posted August 24, 2017 Thanks guys for your help! Quote Link to comment Share on other sites More sharing options...
Hamp Posted August 25, 2017 Share Posted August 25, 2017 (edited) Hey! Happy it worked out Care to share the .hip setup of the loop version? Edited August 25, 2017 by Hamp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.