Skip to content
← Teaching CGI stuff

Code

Short snippets I keep coming back to. VEX first, always the shortest version that does the job. Paste them into a Point Wrangle unless it says otherwise.

VEX — attributes

Random colour per piece

@Cd = rand(i@class);

Needs a class attribute (Connectivity SOP).

Random scale for copies

@pscale = fit01(rand(@ptnum), 0.5, 1.5);
Colour along a curve

@Cd = chramp("ramp", @curveu);

Needs curveu (Resample SOP → Curve U). Click the gear to create the ramp.

Copy an attribute from the nearest point

@Cd = point(1, "Cd", nearpoint(1, @P));

Second input = the geometry you read from.

VEX — shape and placement

Noise along the normal

@P += @N * noise(@P * 4) * 0.2;
Orient copies to the normal

p@orient = quaternion(maketransform(@N, {0,1,0}));
Delete a percentage of points

if (rand(@ptnum) < 0.3) removepoint(0, @ptnum);
Radial mask from a point

f@mask = fit(distance(@P, point(1, "P", 0)), 0, ch("radius"), 1, 0);

Second input = one point (the centre).

VEX — particles

Colour over life

@Cd = chramp("life", @age / @life);

Works in a POP Wrangle or on cached particles.

Python

List every File SOP and its path

for n in hou.node("/obj").allSubChildren():
    if n.type().name() == "file":
        print(n.path(), n.parm("file").eval())

Python Shell or a shelf tool.

Set the frame range

hou.playbar.setFrameRange(1, 240)