You can create dynamic or extension attributes using attribute patterns. An attribute pattern is a description of the dynamic or extension attributes that can be added to any specific node, or node type. This feature removes the need to create each attribute using individual addAttr or addExtension commands.
This feature is supported by the pyJsonAttrPatternFactory.py plug-in.
To use this feature, first create a pattern file. The pattern file lists the attributes that are to be added to a node or node type, and can be in any format that is defined by your plug-in. The Maya plug-in pyJsonAttrPatternFactory.py supports the .json format. Optionally, you can also include a schema file that describes the syntax of the pattern file.
Patterns are simply descriptions of attributes to be copied onto nodes or node types via the applyAttrPattern command.
Some pattern types are defined by a plug-in and are not deleted unless the plug-in is unloaded.
A pattern file can contain more than one pattern and each pattern can contain more than one attribute. When you apply a pattern, all of its attributes are applied and not just a subset. See attrPatternSchema.json for a sample schema file and sampleAttrPatterns.json for a sample pattern file in the devkit/plug-ins/scripted directory of your Developer Kit installation.
The Developer Kit is available online at Autodesk Exchange at https://apps.exchange.autodesk.com/MAYA/en/Home/Index. Copy the Developer Kit archive to a local directory, unarchive it, and copy the folders to your Maya installation directory. Refer to the Setting up your build environment section of the Maya Developer Help for information on how to install and set up the Maya Developer Kit.
Use the createAttrPatterns command to create the set of patterns listed in the pattern file. Then, use the applyAttrPattern command to attach the attributes listed in any one pattern in the pattern file to a node or a node type. The applyAttrPattern command allows you to determine whether to create dynamic or extension attributes. If you list a node name after the command, dynamic attributes are created. If you use the -nt flag to list a node type, extension attributes are created.
Use the listAttrPatterns command to list the available pattern instances and pattern types.
After applying attributes to a node using a pattern, the attributes are no longer associated with the pattern and can only be removed using the deleteAttr or deleteExtension commands and not the deleteAttrPattern command.
Workflow outline for using attribute patterns to create dynamic or extension attributes
The following is a simple sample application of this feature:
[ { "name" : "samplePattern", "attributes" : [ { "name" : "sampleAttr", "defaultValue" : 0.0, "attributeType": "float" } ] } ]
loadPlugin pyJsonAttrPatternFactory.py;
createAttrPatterns –pt “json” –pf “yourfile.json”;
createNode addMatrix; // Result: addMatrix1 // listAttrs; // Result: [the addMatrix attributes] //
applyAttrPattern –pn “samplePattern” “addMatrix1”;
The dynamic attribute sampleAttr is added.
listAttrs; // Result: [the addMatrix attributes] sampleAttr //