addattribute VEX function

Adds or changes a point attribute.

Contexts: pop, sop

  1. void addattribute(string aname, int value)

  2. void addattribute(string aname, float value)

  3. void addattribute(string aname, vector value)

  4. void addattribute(string aname, vector4 value)

  5. void addattribute(string aname, matrix value)

  6. void addattribute(string aname, matrix3 value)

  7. void addattribute(string aname, string value)

  8. void addattribute(string name; float values[]; int capacity, ...)

In Houdini, there are some additional type qualifiers on attributes.

You can specify an additional argument "type" which can be followed by one of the following strings:

"vector"

Instead of an array of 3 floats, this attribute should have special consideration when the geometry is transformed. Examples of vector attributes are N and v. This qualifier is only valid when the attribute being added is a vector.

"indexpair"

The attribute should be considered as a set of index pairs. Currently, only the capture attributes are this type of attribute. This qualifier is only valid when the attribute being added is a vector4 or matrix since an even number of floats should be specified.

Array form

  1. void addattribute(string name; float values[]; int capacity, ...)

This form lets you assign tuples of 2 floats or larger float array to attribute values, such as for capture data.

Since the length of array may be different for each point, the capacity parameter is used to determine the maximum capacity when the attribute is added. If the attribute alreadys exists on the geometry, it will not be altered.

The “type” keyword argument can be used to give additional qualifiers to the attribute (though this only happens when the attribute is first created and the capacity meets certain criteria).

sop
create_attribs()
{
  float   f[] = array(1,2,3,4,5,6,7,8);

  // Add an attribute called "a1" with length 8
  addattribute("a1", f, arraylength(f));

  // Force the attribute size to be 3
  addattribute("a2", f, 3);

  // Set the "vector" qualifier so the attribute is transformed
  // differently.
  addattribute("a3", f, 3, "type", "vector");

  // Set the "index-pair" qualifier (array length must be even)
  addattribute("a4", f, 8, "type", "indexpair");

  // Add some random values in a 2-tuple
  f = array( float(nrandom()), float(random(ptnum)) );
  addattribute("rnd", f, arraylength(f));
}