Create an attribute control using MEL

To create an attribute control using MEL, complete the following steps:

Create the attribute control

In the following example a floatSlider control is created by the MEL procedure AEFloatSlider, and uses the change command AEaddFloatSliderCB.

global proc AEaddFloatSliderCB( string $plug, string $slider ) 
{ 
	float $val = `floatSlider -q -v $slider`; 
	setAttr $plug $val; 
} 

global proc AEaddFloatSlider ( string $plug,
string $label, string $annot )
{

	// Body of callback
	rowLayout -nc 2;
	float $val = `getAttr $plug`;
	string $slider;
	text -label $label;
	$slider = `floatSlider -annotation $annot -v $val`;
	floatSlider -e -cc ("AEaddFloatSliderCB \"" + $plug + "\" \"" + $slider + "\"")
 	$slider;
	 setParent

}

The following parameters are used by the MEL procedure:

Source the MEL procedure

This step provides Maya Creative with the path to the MEL file containing the procedure. If you save the file to a directory called C:/myScripts, type the following into the MEL command line or Script Editor:

source "C:/myScripts/AEFloatSlider.mel";

Tip: You can also give the MEL file the same name as the procedure used in the callback. This allows the file to be sourced the first time that the callback is initiated. For example, if your callback is defined as global proc AEaddFloatSlider(), save the callback file in one of the Maya Creative script directories as AEaddFloatSlider.mel.

Define the callback to the MEL procedure

When you are creating the template file, add a <description language="cb"> tag to an attribute declaration or view definition and specify the callback to the MEL procedure. To add the custom slider control defined in the procedure above to the Incandescence Red attribute use the following:

<attribute name='incandescenceR' type='maya.float'>
    <label>Incandescence Red</label>
      <description language="cb">AEaddFloatSlider</description>
</attribute>
When you access the attribute view in the Attribute Editor, the Incandescence Red attribute uses the customized slider.

Related topics