Adding Custom Attributes

 

custAttributes.add <object_or_collection> <attributes_definition>[#unique] [BaseObject:<bool>]

Adds a set of attributes to an object or a collection. You can only add one custom attribute set of a particular attributes definition to an object, but you can have as many different attribute sets from different definitions as needed.

#unique

When adding custom attributes to an object using the custAttributes.add() function, you can now supply an optional #unique keyword as the third argument. If you do this, each object being added to will have custom attributes added that have their own private copy of the definition and do *not* share the original definition. Any later redefinitions of the original attributes definition will not update these custom attributes. To update the individual object's attributes, you would get the unique definition from the object using custAttributes.getDef, and redefine it in one of the two ways described.

Note:

If you extract the uniquely-added definition, and use it directly in another non-unique custAttributes.add() on some other object, a definition sharing will be set up. Using #unique when adding a global definition will make the added custom attributes non-global, they will have their own private definition which starts out being identical to the original global definition.

BaseObject:<bool>

If the optional keyword argument baseObject is set to true (the default), in case the object specified is a node, the base object will be operated on. If false, the node itself will be operated on.

Note:

In versions prior 3ds Max 5.1, the base object was always used.

 

Example:

custAttributes.add $weapon01 weaponData

Opening $weapon01 in the Modify panel will now display the "Weapon Parameters" rollout and allow them to be edited as can normal object parameters. You can use attribute definitions to add their defined sets of attributes to any object at any time. Any appropriate type of parameter can be animated, also, exactly as with scripted plug-ins.

The custAttributes.add() function can be applied to an object collection to add sets of attributes to a group of objects in one go.

Example:

custAttributes.add $weapon* weaponData

Adds a separate set of these custom attributes to all objects whose names begin "weapon" in the scene.

Note:

Further, an object can have any number of separate sets of custom attributes added from different attribute definitions.

As with Scripted plug-ins, an attributes definition can have any number of sets of parameter and rollout clauses, to allow you to organize added attributes into multiple rollouts as needed.

Scripted custom attributes added to an object or modifier can be accessed via MAXScript. They turn up directly as properties on the objects they are added to. If the names of any of the custom attributes are the same as existing properties on the host object, the custom attributes are effectively hidden when accessed directly. As an alternative, you can access each added block of custom attributes by their attributes definition name and then access individual attributes as properties within that block.

For example,

if the following attributes were added to $box01

the_weaponData = attributes weaponData

(

parameters main rollout:params

(

hitPoints type:#float ui:hits default:10

cost type:#float ui:cost default:100

sound type:#string

)

rollout params "Weapon Parameters"

( ... )

)

the custom attributes could be accessed as

$box01.hitPoints

$box01.cost

$box01.sound

or indirectly through the attributes block:

$box01.weaponData.hitPoints

$box01.weaponData.cost

$box01.weaponData.sound

Next Topic:

Global and Private Custom Attributes Definitions

See also

Scripted Custom Attributes

Custom Attribute Management Functions

Custom Attributes Definition Values

Access to Custom Attributes Virtual Array

Custom Attributes in Materials and Texture Maps