To create an attribute control using the Python global namespace, complete the following steps:
In the following example a slider control is created using Python global namespace methods. The callback is named AEFloatSliderGlobal. A floatSlider control is created by this procedure, and uses the change command AEaddFloatSliderGlobalCB.
def AEaddFloatSliderGlobalCB( plug, slider ): val = cmds.floatSlider( slider, q=1, v=1 ) cmds.setAttr( plug, val ) def AEaddFloatSliderGlobal( plug, sliderLabel, annot ): cmds.rowLayout( nc=2 ) val = cmds.getAttr( plug ) cmds.text( label=sliderLabel ) slider = cmds.floatSlider( annotation=annot, v=val ) cmds.floatSlider( slider, e=1, cc=('AEaddFloatSliderGlobalCB( \"' + plug + '\", \"' + slider + '\" )' ) ) cmds.setParent( u=1 )
The following parameters are used by the procedure:
You must define your Python procedures, so Maya can use them. This can be done by executing the code from the example above in the Python tab of the Script Editor.
When you are creating your custom template file, add a <description language="cb"> flag to the attribute declaration section to specify the callback to the Python procedure. By default, a callback is specified in MEL in the template .
To specify a Python callback called AEaddFloatSliderGlobal in the global namespace, the declaration should be py.AEaddFloatSliderGlobal. The declaration uses the following format: py.<ProcedureName>.
To add the custom slider control defined in the Python module above to the Incandescence Green attribute, use the following:
<attribute name='incandescenceG' type='maya.float'> <label>Incandescence Green</label> <description language="cb">py.AEaddFloatSliderGlobal</description> </attribute>
When you access the attribute view in the Attribute Editor, the Incandescence Green attribute uses the customized slider.
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License