Using Vex to automatically create groups of points from CSV data in Houdini
In my continuing adventures with Houdini I was playing around with this CSV file containing number of kills by James Bond in Bond movies — something I've used before.
I thought it would be handy to create a point group for each actor, so for instance if I wanted to just show the Sean Connery data I could just operate on the group called Sean Connery. I wondered though if there was a smart way of doing this — to create point groups automatically from a certain field / column in the CSV data.
After some playing around I created this Vex code in a Point Wrangle to do exactly that:
// get actors names
string actor = sprintf(s@actor);
// split actors name up into array using space as delimiter
string actorSplit[] = split(actor, " ");
// join array with underscores to create the group name
string groupName = join(actorSplit, "_");
// set group name
setpointgroup(0, groupName, @ptnum, 1, "set");
As it iterates through each row of CSV data (which at this stage is actually point data) it gets the actors name from the actor attribute, splits the name into an array and then I join that array using underscores, so Sean Connery would become Sean_Connery. Finally I then use that string to create a group.
Using this technique I could for example target all the points in the Roger_Moore group, colour them differently, apply a different material etc etc. Hope this may come in handy for others.