vex

Vex can be tricky to learn, especially for those who aren't used to writing code. While houdini's manual does include documentation on vex, the examples don't really show you the correct syntax or leave out information. For instance, look at the documentation for the ch vex function: ch(string channel). If you tried to write this code using the same format, it would not work. This is because strings in vex are supposed to be enclosed in ''. In my opinion, the documentation should be written including the proper syntax like this: ch('string channel').  This problem (in my opinion) makes it difficult to learn vex syntax from the documentation. Even now, the provided examples are confusing to me at times. I am writing this section on vex syntax as reference for me and to help others out there who are just getting started with vex. If anyone from sidefx happens to see this, please consider making the vex documentation a little less confusing : ) A really great resource (which I found more helpful than the documentation) is tokeru.

I will be updating this page regularly, so it might be lacking content at first or I might re-organize after adding new content.

pscale1.png
createp.png

1. Vex makes it really easy to assign attributes to geometry and volumes and gives you both control and customization. Here is an example. Lets say you want to copy geometry to some points using the copy stamp SOP. You need a way to control the size of the copies. Add a attribute wrangle after the source points. The attribute we want to control is "pscale". In the attribute wrangle type in: 
@pscale = 0.5;
When you use an attribute like "pscale" we use the "@" before the attribute. In vex, you end code using a semi-colon. Ok, this is great. What if you don't want to type in values every time you want to make a change? No problem, just use the "ch" function. Type in:
@pscale = ch('scale');
Now click the little icon to the right that looks like a slider and a "+" sign. This button will create a slider for you. If you wondering how I know to do this, I am just following the documentation. If you go to the vex documentation you'll notice a section on attributes and a section on functions. As I stated earlier, they show you an example that only partially follows the correct syntax. 

2. As you use Houdini, you will notice the terms float, integer, and vector. Floats are simply numbers with decimal points (1.0). Integers are numbers without decimal points (1). A vector contains three values, like position and color. For example, you can set a point's position by using a vector:
@P  = {0,1,0};