Houdini 18.5 VEX

Reading attributes

On this page

Without existence check

These functions return the attribute value if the given detail/primitive/point/vertex exists and has the given attribute, or a zero/empty value otherwise.

If you need to distinguish between the attribute value actually being zero/empty vs. the function returning zero/empty value because the attribute didn’t exist, use the checked versions below.

attrib

Reads the value of an attribute from geometry.

<type> attrib(<geometry>geometry, string attribclass, string name, int elemnum)

<type>[] attrib(<geometry>geometry, string attribclass, string name, int elemnum)

This general form lets you specify the attribute "class" at run-time. This can be useful for writing general code that can work on different classes. If you know the class of attribute you want to read ahead of time, using detail(), prim(), point(), or vertex() may be faster.

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribclass

One of "detail" (or "global"), "point", "prim", or "vertex".

You can also use "primgroup", "pointgroup" or "vertexgroup" to read from groups.

name

The name of the attribute, group, or intrinsic to read from.

elemnum

Which element (e.g. point number, primitive number, vertex number) to read from. Ignored for detail attributes. You can use vertexindex() to convert a primitive/point pair into a vertex number.

Returns

Zero/empty value if the attribute does not exist. Use getattrib() if you want to check whether the attribute existed.

detail

Reads the value of a detail attribute value from a geometry.

<type> detail(<geometry>geometry, string attribute_name, int ignored=0)

<type>[] detail(<geometry>geometry, string attribute_name, int ignored=0)

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

ignored

The last argument is always ignored. It is just there so you can change a prim/point/vertex call (which each have an element number argument) to a detail call by changing the name without having to change the arguments as well.

Returns

0 if importing the attribute failed, or the value of the attribute on success.

prim

Reads a primitive attribute value from a geometry.

<type> prim(<geometry>geometry, string attribute_name, int primnumber)

<type>[] prim(<geometry>geometry, string attribute_name, int primnumber)

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

primnumber

The primitive number to read the attribute on.

Returns

The value of the given attribute on the given point number, or 0 if the attribute or point do not exist.

point

Reads a point attribute value from a geometry.

<type> point(<geometry>geometry, string attribute_name, int pointnumber)

<type>[] point(<geometry>geometry, string attribute_name, int pointnumber)

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

pointnumber

The point number to read the attribute on.

Returns

The value of the given attribute on the given point number, or 0 if the attribute or point do not exist.

vertex

Reads a vertex attribute value from a geometry.

<type> vertex(<geometry>geometry, string attribute_name, int linear_vertex_index)

<type>[] vertex(<geometry>geometry, string attribute_name, int linear_vertex_index)

Specifies the vertex using the linear index into the list of all vertices.

<type> vertex(<geometry>geometry, string attribute_name, int prim_num, int vertex_num)

<type>[] vertex(<geometry>geometry, string attribute_name, int prim_num, int vertex_num)

Specifies the vertex as a primitive number and then an offset into the list of vertices on that primitive.

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

Returns

The value of the given attribute on the given vertex, or 0 if the attribute or vertex do not exist.

With existence check

These functions take an additional argument. The functions will overwrite the integer variable you pass to this argument with 1 if the read succeeded or 0 if it failed. This lets you distinguish when the function returns 0 because the attribute value is actually zero, or because the read failed.

If it doesn’t matter in your code whether the attribute doesn’t exist or is actually 0, using the unchecked versions above is slightly easier because you don’t have to create the variable to overwrite.

getattrib

Reads an attribute value from geometry, with validity check.

<type> getattrib(<geometry>geometry, string attribclass, string attribute_name, int elemnum, int &success)

<type>[] getattrib(<geometry>geometry, string attribclass, string attribute_name, int elemnum, int &success)

This general form lets you specify the attribute "class" at run-time. This can be useful for writing general code that can work on different classes. If you know the class of attribute you want to read ahead of time, using detailattrib(), primattrib(), pointattrib(), or vertexattrib() may be faster.

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribclass

One of "detail" (or "global"), "point", "prim", or "vertex".

You can also use "primgroup", "pointgroup" or "vertexgroup" to read from groups.

attribute_name

The name of the attribute (or intrinsic) to read.

elemnum

The point/primitive/vertex number to read the attribute value from. For detail attributes, use 0 here (the argument is ignored for detail attributes).

To get the linear vertex number given a primitive number and the vertex number on the primitive, use the primvertex() function.

success

If the given attribute exists and can be read, the function sets this variable to 1. Otherwise, it sets this variable to 0.

Returns

The value of the attribute.

detailattrib

Reads a detail attribute value from a geometry.

<type> detailattrib(<geometry>geometry, string attribute_name, int ignored, int &success)

<type>[] detailattrib(<geometry>geometry, string attribute_name, int ignored, int &success)

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

ignored

Pass 0 for this argument.

success

The function sets this variable to 1 if the attribute was successfully read, or 0 otherwise.

Returns

0 if importing the attribute failed, the value of the attribute on success.

primattrib

Reads a primitive attribute value from a geometry, outputting a success flag.

<type> primattrib(<geometry>geometry, string attribute_name, int prim, int &success)

<type>[] primattrib(<geometry>geometry, string attribute_name, int prim, int &success)

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

prim

The primitive number.

&success

Set to 1 if the import was successful, 0 on error (for example, the attribute or primitive number don’t exist).

pointattrib

Reads a point attribute value from a geometry and outputs a success/fail flag.

<type> pointattrib(<geometry>geometry, string attribute_name, int pointnumber, int &success)

<type>[] pointattrib(<geometry>geometry, string attribute_name, int pointnumber, int &success)

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

&success

The function overwrites this variable with 1 if the attribute exists and was read successfully, or 0 otherwise.

Returns

The value of the given attribute on the given point number, or 0 if the attribute or point do not exist.

vertexattrib

Reads a vertex attribute value from a geometry.

<type> vertexattrib(<geometry>geometry, string attribute_name, int linear_vertex_index, int &success)

<type>[] vertexattrib(<geometry>geometry, string attribute_name, int linear_vertex_index, int &success)

Unlike vertex(), this function does not have a version that takes a primitive number and primitive vertex number. If you have a primitive number and primitive vertex number, you can convert them into a linear index using vertexindex().

<geometry>

When running in the context of a node (such as a wrangle SOP), this argument can be an integer representing the input number (starting at 0) to read the geometry from.

Alternatively, the argument can be a string specifying a geometry file (for example, a .bgeo) to read from. When running inside Houdini, this can be an op:/path/to/sop reference.

attribute_name

The name of the attribute (or intrinsic) to read.

linear_vertex_index

A linear index into the list of all vertices. If you have a primitive number and primitive vertex number, you can convert them into a linear index using vertexindex().

success

The function overwrites this variable with 1 if the attribute exists and was read successfully, or 0 otherwise.

Returns

The value of the given attribute on the given point number.

Examples

// Get the value of the "uv" attribute for the detail.
vector uv = detail("defgeo.bgeo", "uv");
// Get the value of the "Cd" attribute for primitive 7
// in the SOP specified by the path "/obj/geo1/color1" (Houdini
// only)
vector clr = prim("op:/obj/geo1/color1", "Cd", 7);
// Get the position of point 3 in "defgeo.bgeo"
vector pos = point("defgeo.bgeo", "P", 3);
// Get the value of the "uv" attribute for vertex 2 of primitive
// number 3 in the file defgeo.bgeo
vector uv = vertex("defgeo.bgeo", "uv", 3, 2);

VEX

Language

Next steps

Reference