I want to create an arbitrary number of groups based on an attribute using VEX. The basic set-up is pretty simple:
Put down some Geo > Scatter arbitrary number of points on Geo > Feed those points into POPNet > Feed particles from POPNet into a Trail SOP > Use Add SOP to create lines from particle trails by grouping by attribute (id). That works great but I want to use VEX to create the groups instead of using the Add SOP.
My problem is that I haven't been able to figure out the correct VEX syntax, in particular, how to set the group name to the @id attribute (each trail inherits the @id of the originating particle) like so:
i@startpoints = chi(“../scatter1/npts”); // get the number of scattered points
s@test = itoa(@id); // convert id to string
for (int i=0; i < @startpoints+1; i++){ // loop over points
s@groupname = concat(“group_”, @test); // this creates strings matched to @ids, e.g., group_0
// not what I need
if (i==@id){
i@group_***** = 1; // ***** is where I'm stuck, how to read i into the groupname
} // I thought I could use ` ` to read it in but that fails. ?
}
I can achieve the effect I need with the Add SOP but I feel like I'm missing something in my understanding of VEX here and would love to sort it out. Any help would be much appreaciated.
Using VEX to create groups by attribute
65020 14 6- kevinthebright
- Member
- 213 posts
- Joined: 11月 2010
- Offline
- BabaJ
- Member
- 2127 posts
- Joined: 9月 2015
- Offline
Maybe try using the vex function setpointgroup:
http://www.sidefx.com/docs/houdini/vex/functions/setpointgroup [sidefx.com]
Edit: Also, I've noticed that on your line;
It looks like your trying to assign 1 to a string. Maybe 1 can't be implicitly cast?
http://www.sidefx.com/docs/houdini/vex/functions/setpointgroup [sidefx.com]
Edit: Also, I've noticed that on your line;
s@concat(“group_”,@test") = 1; // create group for each id - this doesn't work
It looks like your trying to assign 1 to a string. Maybe 1 can't be implicitly cast?
Edited by BabaJ - 2017年4月10日 12:53:16
- kevinthebright
- Member
- 213 posts
- Joined: 11月 2010
- Offline
Hi BabaJ,
Thanks! Setpointgroup works perfectly! The string concat work (creates the string). I meant it didn't accomplish what I needed. I'll edit to clarify that. Here's the final code in case its helpful for others.
i@startpoints = chi(“../scatter1/npts”);
s@test = itoa(@id);
for (int i=0; i < @startpoints+1; i++){
s@groupname = concat(“group_”, @test);
if (i==@id){
setpointgroup (0, @groupname, @ptnum, 1, “set”);
}
}
Thanks! Setpointgroup works perfectly! The string concat work (creates the string). I meant it didn't accomplish what I needed. I'll edit to clarify that. Here's the final code in case its helpful for others.
i@startpoints = chi(“../scatter1/npts”);
s@test = itoa(@id);
for (int i=0; i < @startpoints+1; i++){
s@groupname = concat(“group_”, @test);
if (i==@id){
setpointgroup (0, @groupname, @ptnum, 1, “set”);
}
}
- jsmack
- Member
- 8041 posts
- Joined: 9月 2011
- Offline
Why are you binding all of your variables to attributes, is this just for testing?
You also appear to be looping over the points, and comparing index to id. Normally, you can just bind id since you are building the group name directly from id anyways.
your code can be simplified to:
You also appear to be looping over the points, and comparing index to id. Normally, you can just bind id since you are building the group name directly from id anyways.
your code can be simplified to:
string prefix = chs("prefix"); string groupname = sprintf("%s_%d", prefix, @id); setpointgroup(0, groupname, @ptnum, 1);
- kevinthebright
- Member
- 213 posts
- Joined: 11月 2010
- Offline
- BabaJ
- Member
- 2127 posts
- Joined: 9月 2015
- Offline
Hi kevinthebright:
I suspect you already know this…but if in cases where the only reason you bind a ‘variable’ so that you can see it in the spreadsheet; There is another option.
I sometimes create Detail Attributes for ‘data sets’ in vex to be used multiple times elsewhere in my Network but have no need for the points, prims or say vertices that the data was derived from (in the context that I am using the data sets.)
In those cases when they are not bound they still show up and are available to view in the spreadsheet under the Detail tab.
I suspect you already know this…but if in cases where the only reason you bind a ‘variable’ so that you can see it in the spreadsheet; There is another option.
I sometimes create Detail Attributes for ‘data sets’ in vex to be used multiple times elsewhere in my Network but have no need for the points, prims or say vertices that the data was derived from (in the context that I am using the data sets.)
In those cases when they are not bound they still show up and are available to view in the spreadsheet under the Detail tab.
- kevinthebright
- Member
- 213 posts
- Joined: 11月 2010
- Offline
- Felix6699
- Member
- 45 posts
- Joined: 8月 2012
- Offline
- kevinthebright
- Member
- 213 posts
- Joined: 11月 2010
- Offline
Hi Felix6699
Here I set up some colors, then create 3 groups, an allPoints group, a neg_zed group and red group, then call the neg_zed group in an if loop. Does that help?
Also, as ever, check out Matt's blog:
http://www.tokeru.com/cgwiki/index.php?title=HoudiniVex#Access_group_names_procedurally_in_vex [tokeru.com]
Here I set up some colors, then create 3 groups, an allPoints group, a neg_zed group and red group, then call the neg_zed group in an if loop. Does that help?
@Cd = set (0, 0, 1); if (@P.x > 0){ @Cd.r = 1; } i@group_allPoints = 1; i@group_neg_zed = @P.z < 0; i@group_red = @Cd.r > 0.6 ? 1 : 0; if (@group_neg_zed == 1){ @Cd = @P.z; }
Also, as ever, check out Matt's blog:
http://www.tokeru.com/cgwiki/index.php?title=HoudiniVex#Access_group_names_procedurally_in_vex [tokeru.com]
- Felix6699
- Member
- 45 posts
- Joined: 8月 2012
- Offline
- BabaJ
- Member
- 2127 posts
- Joined: 9月 2015
- Offline
Hello! I'm little confused with reading existing group in vex editor (Attribute Wrangle). Can't find in documentation mention of this. Example:
Not sure what you mean by ‘reading’ but there is an easy way to get points, primitives or edges from an existing group in vex;
expandpointgroup
expandprimgroup
expandedgegroup
http://www.sidefx.com/docs/houdini/vex/functions/expandpointgroup [sidefx.com]
http://www.sidefx.com/docs/houdini/vex/functions/expandprimgroup [sidefx.com]
http://www.sidefx.com/docs/houdini/vex/functions/expandedgegroup [sidefx.com]
- tamte
- Member
- 8785 posts
- Joined: 7月 2007
- Offline
Felix6699http://www.sidefx.com/docs/houdini/vex/snippets#accessing-group-membership [sidefx.com]
Strange, that I missed it somewhere in the documentation
http://www.sidefx.com/docs/houdini/nodes/sop/groupexpression [sidefx.com]
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- Onyro
- Member
- 9 posts
- Joined: 11月 2020
- Offline
kevinthebright
string prefix = chs("prefix");
string groupname = sprintf("%s_%d", prefix, @id);
setpointgroup(0, groupname, @ptnum, 1);
Hi Kevin, so i have used this code to create point attributes with lets say "group_0", "group_1" etcc but i want to convert these point attributes to actual groups... so basically the points i have assigned an attribute "group_0" to convert them into a point group with the same name...
any help would be greatly appreciated... thanks!
- kevinthebright
- Member
- 213 posts
- Joined: 11月 2010
- Offline
OnyroHi Onyro, By actual groups, I take it you are not seeing the groups when you click on the node information? Is your wrangle after the trail SOP? You should be able to create a group from any attribute with the i@group_groupname = 1 syntax. For example, i@group_blueteam = (@Cd.b == 1) ? 1 : 0; sets a points membership to the blueteam group if point's blue color value is 1. Post your hip if you get stuck.
i want to convert these point attributes to actual groups
- MarcoMeeuwse
- Member
- 5 posts
- Joined: 9月 2015
- Offline
So, is it also possible to use the created group immediately. So in the same wrangle? Instead of using multiple wrangles and selecting the group.
Lets say something like this?
if(@P.z <= 0)
{
i@group_max = 1;
}
if(@P.z >= 0)
{
i@group_min = 1;
}
// just a sample expression
if(i@group_max=1)
{
@Cd = set(0,1,0);
}
if(i@group_min=1)
{
@Cd = set(0,0,1);
}
Lets say something like this?
if(@P.z <= 0)
{
i@group_max = 1;
}
if(@P.z >= 0)
{
i@group_min = 1;
}
// just a sample expression
if(i@group_max=1)
{
@Cd = set(0,1,0);
}
if(i@group_min=1)
{
@Cd = set(0,0,1);
}
-
- Quick Links