Groups as attributes in VEX

 The previous example uses attributes as groups. You can go the other way and use groups as attributes. Look in the geometry spreadsheet, you'll see colums for groups. An element will have a value of 1 if it's in the group, 0 if it's not.


To use this in vex you refer to the pseudo attribute @group_yourgroup.


Eg you have a (vex) attribute wrangle node, and you want to run some code only for points NOT in group 'mygroup':


if (!i@group_mygroup) {
    // do thing
}


Ie, you can refer to the group by using '@group_' as a prefix. Don't overthink the syntax btw, its literally @, type the word 'group', then underscore, then your group name, no spaces.


Calling it as a conditional here uses a little trick, cast it to an int, and negate it (that's the 'i' before the '@').


You can also create groups in a similar way with a wrangle node; just pretend you're creating an attribute and setting it to 1, houdini will make a group for you. Eg



if (@ptnum>chi('threshold')) {
 i@group_mygroup=1;
}






I learned this ages ago, forgot, learned it again, forgot, learned again. If you're skimming this page for the first time, you'll forget too, and relearn it a few months later. :)


Very briefly covered in the docs here (along with lots of other handy vex tips):




0 Commentaires