keywords: Houdini, Expression, VEX

##### Basic Notes

How to view VEX source code of VOP:

How to change point position:
Run Over: `Points`.

``````vector pos = @P;
if(pos.x < -3.5)
{
@P = set(@P.x, @P.y + 5, @P.z);
}
``````

How to remove points on polygon:
Run Over: `Points`.

``````if(@P.x < 250 && @P.z < 250 && @P.y > 250)
{
removepoint(0, @ptnum);
}
``````

How to remove primitive:
Run Over: `Primitives`.

``````if(@Frame > 5 && @P.z >10)
{
removeprim(0, @primnum, 1);
}
``````

How to add and set customized variables for points, vertices or primitives.

``````//add and set
i@my_var = 1;
//get
printf("%d\n", i@my_var);
``````

How to set transform of primitives:
Run Over: `Primitives` or `Points`.

``````float scale = 1.5;
matrix transform = getpackedtransform(0, @primnum);
scale(transform, set(scale, scale, scale));
setpackedtransform(0, @primnum, transform);
``````

How to rotate a point around another point alone a specifical axis：
1st way:

``````float angle = -90;
vector4 rot = quaternion(radians(angle), {1, 0, 0});
@P = qrotate(rot, @P + set(0, -500, -500));
``````

2nd way:

``````matrix mat = maketransform(set(0, 1, 0), set(0, 0, -1), set(0, -tile_size, tile_size));
@P *= mat;
``````

How to move a point alone normal:

``````@P += @N * chf('dist');
``````

### Points Computation

##### Snap an object to another precedurally
``````int pt = nearpoint ( 1, @P );
vector p = point ( 1, "P", pt );

@dist = distance2 ( @P, p );
i@nearpt = pt;
``````

Sort by dist attribute.
Move wrangle code:

``````int pt = point ( 1, "nearpt", 0 );

vector p0 = point ( 1, "P", 0 );
vector p1 = point ( 2, "P", pt );

@P += p1 - p0;
``````
##### Documents

HOUDINI help
https://www.sidefx.com/docs/houdini19.5/

Using VEX expressions
https://www.sidefx.com/docs/houdini/vex/snippets.html

Parameter expressions
https://www.sidefx.com/docs/houdini/network/expressions.html

Popular Built-in VEX Attributes (Global Variables)
https://stephanosterburg.gitbook.io/scrapbook/untitled/popular-built-in-vex-attributes-global-variables

##### Tutorials

The Nature of Vex.
https://www.mixtrn.com/nature-of-vex

##### Blogs

【Houdini】 表达式与VEX变量
https://www.yuelili.com/houdini-expression-and-vex-variable/

Houdini: Remove Outside Pieces Using Python
https://yudaitamamura.artstation.com/blog

houdini attributes cheatsheet
https://gist.github.com/iinfin/2caf4e2ccb2545477670e88ddacee1e2

##### Personal Notes (Tricks)

Killian Timsit
https://gist.github.com/killiantimsit

VEX for artists
https://github.com/kiryha/Houdini/wiki/vex-for-artists

`“How can I be substantial if I do not cast a shadow? I must have a dark side also If I am to be whole.” ― C.G. Jung, Modern Man in Search of a Soul`