I'm creating a new plugin which has a number of attributes that require special handling. Looking through other objects and the tutorials I'm not quite sure how to do it.
For instance, one attribute is a filename. I created this as a string and it doesn't appear in the channel editor but does appear if I select the object Attribute Editor. As it is a filename, I would like to have a 'browse' button appear next to it so a user can select the file. Also, I need two other buttons to 'play' and 'stop' as this is an audio file, so sounds can be previewed in Maya.
I can see how to do this with a custom window created in MEL but what about an object that has been created? How do I get my attribute editor to appear instead of the standard one - or is that the wrong question?
On your plugin node, your attributes are all static MObjects. In your initialise function you create these attributes on your node (ish). If we take the example of creating a string on a node, your class should hold a variable like :
static MObject aStringAttribute;
In the initialise function we need to let Maya know we've created it. We need a function set for the attribute type in order to create it...
MFnAttribute tAttr;
now we need to create the attribute, specifiying its maya long & short name, as well as the data type :
we are then able to set a number of flags to say what the attributes properties are,
// can it be key framed tAttr.setKeyable(false);
// should it be stored in the Maya Binary file tAttr.setStorable(true);
// is it hidden tAttr.setHidden(true);
// can it recieve incoming connections.. tAttr.setConnectable(false);
// is it an array, setting this to true gives you an array of strings tAttr.setArray(true);
The above stuff will create the attribute, but the next thing we need to do is add the attribute to the node :
addAttribute( aStringAttribute );
The next thing you do is set up the dependanciies between nodes. For example, if you had an attribute for inColor, when it changed you'd want maya to re-calculate the outColor, you'd add a line like :
attributeAffects ( aInColor, aOutColor );
attributes will only appear in the channel box if they are keyable.
In addition to your node will be an attribute editor template. This should be called AEsomeNodeTemplate.mel and will need to be placed in your maya scripts directory. you'll need to make use of the editorTemplate mel command and use it to create custom controls in the Attribute editor. The best thing to do is look in the "C:AWMaya4.0scriptsAETemplates" directory and have a look at some templates that have already been created.
the simplest template would look like :
global proc AEsomeNodeTemplate ( string $nodeName ) { // start scroll bar gubbins // editorTemplate -beginScrollLayout;
// add you attributes here.....
// use "editorTemplate -callCustom" for your own controls
// add controls for all other attributes
editorTemplate -addExtraControls;
// end the scroll layout....
editorTemplate -endScrollLayout;