Brendan Dawes
The Art of Form and Code

Moving all the points in a Houdini primitive using Vex

This is just a quick one but wanted to note this down for future reference.

Sometimes it's handy to be able to manipulate all the points in a primitive, in order to move the position of that promitive or multiple primitives. You can do this in various ways, including using the Primitive sop, but this is how you do it using Vex.

Firstly wire in a Primitive Wrangle, so the Vex code is running over each primitive in the scene.

To then get all the points for each primitive, and move them, you can do this:

int points[] = primpoints(0,@primnum);
int ll = len(points);

for(int i=0; i<ll;i++)
{
    vector p;
    p = getattrib(0,"point", "P", points[i], 0);

    float x = p.x;
    float y = p.y;
    float z = noise(@primnum/3000.0)*0.6;

    vector move = set(x,y,z);
    setpointattrib(0,"P",points[i],move, "set");

}

In this example I'm using some noise to move the primitive in the Z axis.

I think I found this on a forum somewhere but now can't quite remember. Hope this comes in handy for someone.