Assign to a custom attribute

You can add a custom attribute to a particle shape node and control its value in an expression.

To add a custom attribute:

  1. Select the object’s particle shape node rather than its transform node.

    Use the Hypergraph or Outliner to select the shape node.

  2. Do one of the following:
    • Select Modify > Add Attribute.
    • In the Add Dynamic Attributes section of the Attribute Editor, click the General button.

    The Add Attribute window appears:

  3. Enter a name for the attribute in the Long name box.
  4. Make sure Make attribute: Keyable is on.
  5. Select one of the following data types:
    Vector

    Creates a vector attribute consisting of three floating point values.

    Float

    Creates a floating point attribute.

    Integer

    Creates an integer attribute.

    Boolean

    Creates an attribute consisting of an on/off toggle.

    String

    Creates a string attribute that accepts alphanumeric entries as data entry.

    Enum

    Creates an attribute that accepts selections from an “enumerated” or drop-down list.

  6. Select one of the following attribute types:
    Scalar

    Creates a per object attribute that you can set to a single value that applies to every particle in the object. A vector scalar is considered a single value with three numbers.

    Per particle (array)

    Creates a per particle attribute. You can set this type of attribute to different values for each particle.

    • If you select Scalar, you can specify Minimum, Maximum, and Default values for a Float or Integer attribute.

      Minimum and Maximum set the lowest and highest values you can enter for the attribute in the Attribute Editor or Channel Box. Default sets the default value displayed for the attribute. Because you’re going to control the attribute’s value with an expression, you might want to skip entering values for these options.

      An expression isn’t bound by the Minimum and Maximum values. The attribute receives whatever value you assign it in the expression. The expression can read the attribute’s Default value or any other value you give it in the Attribute Editor or Channel Box.

      When you select Scalar, you can’t create a counterpart initial state attribute by turning on Add Initial State Attribute.

    • If you select Per particle (array), you can also create a counterpart initial state attribute by turning on Add Initial State Attribute. See Understand initial state attributes for details.

      You can’t set Minimum, Maximum, or Default values for an Array attribute.

  7. Click Add if you want to add more attributes. Click OK to add the attribute and close the Add Attribute window.

    The new attribute appears under the Extra Attributes section of the Attribute Editor. Although the attribute name is always spelled with an uppercase first letter in the Attribute Editor, you must use the exact spelling shown in the Expression Editor, whether lowercase or uppercase.

To assign values to a custom attribute

    You can assign values to a custom attribute with the same techniques you use to assign values to static or dynamic attributes.

Example

Suppose you’ve created a 10-particle object named sunspot, and you add to its particle shape node a float scalar (per object) attribute named glow. You assign the glow attribute a value in a creation expression as follows:

sunspotShape.glow = 11.5;
print (sunspotShape.glow + "\n");

When you rewind the animation, the glow attribute of sunspotShape receives the value 11.5. The print statement displays the value in the Script Editor. The value appears 10 times because the expression executes once for each particle in the object.

Example

Suppose you add a vector array (per particle) attribute named heat to the 10-particle sunspot shape node. You can give each particle a different value as in this creation expression:

float $randomNumber = rand(1);
sunspotShape.heat = <<$randomNumber,0,0>>;
print(sunspotShape.heat + "\n");

When you rewind the animation, the expression loops through 10 executions, once for each particle.

The first statement sets the $randomNumber variable to a random number between 0 and 1. The next statement assigns a vector to the heat attribute of a single particle. The left component of the vector assigned to heat is a different random number each time the statement executes. The middle and right components are always 0.

One particle might have the value <<0.57, 0, 0>>, another <<0.32, 0, 0>>, another <<0.98, 0, 0>>, and so on.

The print statement displays the values in the Script Editor.

Note:

If you add a custom vector attribute to an object, Maya displays the attribute in the Attribute Editor, but you can’t enter its value there. You must enter a value for it in an expression or with the Component Editor available from the Attribute Editor.