Laurent Crivello
Laurent Crivello

Reputation: 3931

Group custom attributes to nodes in Maya

I am writing a Maya plugin in c++, and have a custom MPxLocatorNode.
I have added numerous custom attributes to this node with:

   MFnNumericAttribute nAttr;

    Attrib1 = nAttr.create( "Attribute1", "att1", MFnNumericData::kInt,1.0 );
    nAttr.setKeyable(false);
    nAttr.setStorable(true);
    nAttr.setReadable(true);
    nAttr.setWritable(true);
    nAttr.setHidden(false);
    addAttribute( unitId );

    Attrib2 = nAttr.create( "Attribute2", "att2", MFnNumericData::kInt,1.0 );
    nAttr.setKeyable(false);
 ...

However I need to add plenty of these attributes and would therefore like to group them when displayed in the attribute editor. Is there a way to dynamically create groups or separators ?

Upvotes: 0

Views: 1609

Answers (1)

cyrille
cyrille

Reputation: 2659

I am a bit confused by the word grouping, but I'll answer the 2 grouping options.

The first one is to group attributes as a compound. A good example of a compound is a point compound. In short you got a point attribute which owns 3 double attributes. So the x, y, z coordinates are grouped under the Point attribute. If now you go in the Channel Editor, you'll see the grouping effect. In the Attribute Editor and for known / predefined types, controls will be assigned automatically, doing some grouping as well.

Now, and because you mentioned the Attribute Panel, I think you are more interested on how you teach the Attribute Editor to have a different layout than the default one. If you create an AE<my custom node name>Template.mel file, with a function of the same name in it, then you can take control on how the layout is done and group, show, hide, change controls of each individual attributes.

For example I got a custom node which you can download from here. Since it is Python and MEL, you can get the full source code from there.

The node name is adskMathNode. So I created a AEadskMathNodeTemplate.mel file. This file contains a function declare like this:

global proc AEasdkMathNodeTemplate (string $nodeName) {
    editorTemplate -beginScrollLayout ;
    ...
}

This is where you describe the new layout. You'll get plenty of bigger example in the Maya folder at /scripts/AETemplates

Upvotes: 3

Related Questions