top of page

VEXpressions

  • Writer: Sammy Lyu
    Sammy Lyu
  • Aug 5, 2025
  • 3 min read

Updated: Dec 5, 2025

This section focuses on VEXpressions


As of writing, my Houdini version is 20.5.614





FIT01 and RAND to create randomisation for point and prim values


The fit01 function allows us to specify and certain range of values.

The RAND function randomly selects a value between that range.

Together, they are able to randomise the value within a range for a certain attribute.


This is an example for the attribute, air resistance (airresist):


airresist = fit01(rand(@ptnum+24), 0.1, 0.2);


This function creates a random value between 0.1 and 0.2 for the air resistance property at the currently active point number, offset by a value of 24.



POINT VELOCITY MANIPULATION (Cut, multiply, reverse)



To CUT VELOCITY from a geometry, you can use the vexpression: @v *=0.5; (this example cuts velocity down by half) sometimes you will see v@v, that is simple a redundant way to refer to @v in older versions of Houdini.



Stating MULTIPLE CONDITIONS on an IF function


To create TWO CONDITIONS on an IF function, you can use the && (double ampersands): if(@age < 0.1 && length(@v)>ch("Speed")) {

@v = 0; }


This basically say that if the AGE attribute is less than one AND the velocity is higher than the value present in the "Speed" channel, then velocity = 0.


Specifying a specific STRING value in VEX


When using VEX to specify STRINGS, you should use two equal signs like this ==


if(s@object=="floor") {@v *=0.5;}



Referencing DIRECT INPUTS of a DOPNET with VEX


Usually a DOP object can reference geoemetries from the 4 inputs of the DOPNET using “context geometries”, but if that option is not available, for example in “Vellum source”, we can instead use the expression:


 `opinputpath(“..”,0)


This tell the source to look at the first input of the DOPNET for the reference geometry. “0” means first input, “..” means two level up.



Using VEX to match trail length to trail increment


In the trail SOP, you can use the following VEXpression to make sure the trail length is always RELATIVE to the trail increment:


1/ch("inc") - this always ensure that the trail length is always 1 divided by the increment val.


This makes the trail look more mathematically correct and eliminates guess work.



Creating a new channel to reference attributes in VEX


To create a new "CHANNEL" parameter that references any attribute and can be visualised by a slider, you can use the following VEXpression: string @attribute = chf ("yourchannelname") This example above creates a channel for the string value called "attribute" labelled "yourchannelname" Here is an example created for the name attribute:











Substraction in VEX


The symbol -= means SUBSTRACTION in VEX


So if a value was -= to something, it means that value subtracted by the value that follows the symbol. For example, @v -= 50; means that we subtract 50 from the original velocity.



Evaluating a VEX code without leaving the input window


Usually when you click out of the attribute wrangle window after inputting a VEX code, the scene view updates the results. But you could also press CTRL + ENTER to evaluate the result instantly while still typing the code, saving time.



Cleaning up codes by assigning VARIABLES

Let's say you want to assign a RAND function to the color of a ptnum according to a parameter called "Scale". Naturally you would do this: @Cd = RAND( float(@ptnum) / ch("scale"));

But instead, you can make this line more concise by already determining the float variable "num" inside the RAND function, as follows: float num = float(@ptnum) / ch("scale"); @Cd = RAND(num); With this referencing, we can use the rand function on a pre-determined float value called "num" instead of needing to type it out again everytime we do a RAND function.

Curly brackets in VEX

When you have something in a curly bracket like this: distance (@P, {1,1,1} ); It means that it is a VECTOR, as in X, Y, Z or Y, U, V.


Curly brackets is how you set vectors in VEX.



Defining DATA TYPE when creating attributes for SOLVERS When creating attributes such as ACTIVE and ANIMATED or DEFORMING. You would usually write:

@active = 1;

@animated = 1; Without specifying a DATA TYPE, these values default to a FLOAT. But for solvers like RBD, they only take INTEGERS for some attributes. So to make sure the right data type is selected for the attribute, always define it: i@active = 1;

i@animated = 1;

The "i" makes it so that the attribute is defined as an "INTEGER". Same goes for floats and vectors - "f" and "v".



 
 
bottom of page