On this page |
runVex(vex_file, inputs, precision="32")
→ dict
of str
to values
Arguments ¶
vex_file
A string containing the path to a compiled VEX object file (.vex
) on disk. This function does not accept VEX source code (.vfl
), you must compile the source code first.
Currently this function only works with functions in the cvex
context.
runVex
currently raises an exception if the file path does not end with .vex
.
Note
runVex
always calls the “main function” in the compiled file (the function whose return type is the context type, cvex
). It is not currently possible to call another function in the compiled file by name.
inputs
A dictionary mapping VEX input names to values.
-
If a value is a single number, string, hou.Vector3, hou.Vector4, hou.Matrix3, or hou.Matrix4, it is treated as a “static” value.
-
If a value is a sequence of values, it is treated as varying data the function will “iterate over” (possibly in parallel) automatically. This is the same as when, for example, a VEX snippet runs over all the points in a geometry. It is more efficient to call the function once with varying data than to call it separately for each of a list of different values.
-
If you supply multiple “varying” inputs, they must all be the same length and all values must be the same type. Houdini iterates over the corresponding values at each index of the varying sequences.
For example, you might have two arguments corresponding to a point’s color (
Cd
) and position (P
) attributes:runVex("test.vex", { "Cd": [hou.Vector3(1.0, 0, 0), hou.Vector3(0, 1.0, 0), hou.Vector3(0, 0, 1.0)], "P": [hou.Vector3(1.0, 1.0, 1.0), hou.Vector3(2.0, 2.0, 2.0), hou.Vector3(3.0, 3.0, 3.0)] })
Houdini would “zip” the two lists together and iterate using the following values:
Iteration
Cd
P
1
Vector3(1.0, 0, 0)
Vector3(1.0, 1.0, 1.0)
2
Vector3(0, 1.0, 0)
Vector3(2.0, 2.0, 2.0)
3
Vector3(0, 0, 1.0)
Vector3(3.0, 3.0, 3.0)
Note
Because this function interprets a sequence as varying data, it is not currently possible for this function to call VEX with array arguments.
precision
Either "32"
or "64"
. If you specify "64"
Houdini will run the VEX snippet in 64-bit mode.
Returns ¶
runVex()
returns a dictionary mapping VEX output names to values.
The “main” VEX function does not directly return values, it can only write to arguments marked export
. This dictionary contains the output value of the exported arguments.
If the input to the argument was static, the output will be a single value. If the input to the argument was “varying”, the output will be a tuple of values. If multiple arguments were varying, the output tuples will all be the same length.
Example ¶
For example, if you have the following code.vfl
file and compile it to code.vex
using vcc:
cvex add(float x=0; float y=0; export float out=0) { out = x + y; }
You can then invoke it from Python using the following:
>>> hou.runVex("code.vex", {"x":(1.0, 2.0, 3.0), "y":(7.1, 8.1, 9.1)}) {"out": (8.1, 10.1, 12.1)} >>> hou.runVex("code.vex", {"x":(1.0, 2.0, 3.0), "y":0.5}) {"out": (1.5, 2.5, 3.5)} >>> hou.runVex("code.vex", {"x":1.0, "y":0.5}) {"out": 1.5} >>> hou.runVex("code.vex", {"x":1.0, "y":0.5}, precision="64") {"out": 1.5}
Using a VOP network ¶
The following code shows how you can write the VEX code created by a VOP network node (such as a CVEX VOP) to a file, for use with runVex
:
import os import tempfile def runVexFromNode(vop_node, input_dict): handle, path = tempfile.mkstemp(prefix=vop_node.name(), suffix=".vex") vop_node.saveCompiledCookCodeToFile(path) os.close(handle) output_dict = hou.runVex(path, input_dict) os.remove(path) return output_dict