Most of the custom nodes and commands that form part of the AL_usdmaya plug-in utilize helper classes to automate some of the boiler plate aspects of the Maya API. These include:
Typically within Maya most MEL commands end up being exposed to the user via a fairly standard pattern, where by you have a menu item on a menu somewhere, along with an option box that allows you to configure some preferences that are stored between Maya sessions. The MEL code needed to implement this is not overly complicated, but it can be rather tedious, and occasionally prone to errors.
As a way to minimize the possibility of bugs, most MEL commands within the USD maya bridge have an auto generated GUI to go along with them.
AL::maya::utils::CommandGuiHelper commandGui("AL_usdmaya_ProxyShapeImport", "Proxy Shape Import", "Import", "USD/Proxy Shape/Import", true);
commandGui.addFilePathOption("file", "File Path", AL::maya::utils::CommandGuiHelper::kLoad, "USD Ascii (*.usd) (*.usd)", AL::maya::utils::CommandGuiHelper::kStringMustHaveValue);
commandGui.addStringOption("primPath", "USD Prim Path", "", false, AL::maya::utils::CommandGuiHelper::kStringOptional);
commandGui.addStringOption("excludePrimPath", "Exclude Prim Path", "", false, AL::maya::utils::CommandGuiHelper::kStringOptional);
commandGui.addStringOption("name", "Proxy Shape Node Name", "", false, AL::maya::utils::CommandGuiHelper::kStringOptional);
commandGui.addBoolOption("connectToTime", "Connect to Time", true, true);
commandGui.addBoolOption("unloaded", "Opens the layer with payloads unloaded.", false, true);
All of that auto generates a series of MEL functions that in total make our GUI. Below is an annotated version of the generated MEL script.
global proc build_AL_usdmaya_ProxyShapeImport_optionGUI()
{
if(`window -q -ex "AL_usdmaya_ProxyShapeImport_optionGUI"`) return;
$window = `window -title "Proxy Shape Import" -w 550 -h 350 "AL_usdmaya_ProxyShapeImport_optionGUI"`;
$menuBarLayout = `menuBarLayout`;
$menu = `menu -label "Edit"`;
menuItem -label "Save Settings" -c "save_AL_usdmaya_ProxyShapeImport_optionGUI";
menuItem -label "Reset Settings" -c "reset_AL_usdmaya_ProxyShapeImport_optionGUI";
setParent $window;
$form = `formLayout -numberOfDivisions 100`;
$columnLayout = `frameLayout -cll 0 -bv 1 -lv 0`;
rowLayout -cw 1 170 -nc 2 -ct2 "left" "right" -adj 2 -rat 1 "top" 0 -rat 2 "top" 0;
columnLayout -adj 1 -cat "both" 1 -rs 2;
build_AL_usdmaya_ProxyShapeImport_labels();
setParent ..;
columnLayout -adj 1 -cat "both" 1 -rs 2;
build_AL_usdmaya_ProxyShapeImport_controls();
setParent ..;
setParent ..;
setParent ..;
$rowLayout = `paneLayout -cn "vertical3"`;
$doit = `button -label "Import" -c ("save_AL_usdmaya_ProxyShapeImport_optionGUI;execute_AL_usdmaya_ProxyShapeImport_optionGUI;deleteUI " + $window)`;
$saveit = `button -label "Apply" -c "save_AL_usdmaya_ProxyShapeImport_optionGUI"`;
$close = `button -label "Close" -c ("deleteUI " + $window)`;o
setParent ..;
formLayout -e
-attachForm $columnLayout "top" 1
-attachForm $columnLayout "left" 1
-attachForm $columnLayout "right" 1
-attachControl $columnLayout "bottom" 5 $rowLayout
-attachForm $rowLayout "left" 5
-attachForm $rowLayout "right" 5
-attachForm $rowLayout "bottom" 5
-attachNone $rowLayout "top"
$form;
init_AL_usdmaya_ProxyShapeImport_optionGUI();
load_AL_usdmaya_ProxyShapeImport_optionGUI();
showWindow;
};
global proc init_AL_usdmaya_ProxyShapeImport_optionGUI()
{
if(!`optionVar -ex "AL_usdmaya_ProxyShapeImport_connectToTime"`)
optionVar -iv "AL_usdmaya_ProxyShapeImport_connectToTime" 1;
if(!`optionVar -ex "AL_usdmaya_ProxyShapeImport_unloaded"`)
optionVar -iv "AL_usdmaya_ProxyShapeImport_unloaded" 0;
};
global proc save_AL_usdmaya_ProxyShapeImport_optionGUI()
{
optionVar -iv "AL_usdmaya_ProxyShapeImport_connectToTime" `checkBox -q -v AL_usdmaya_ProxyShapeImport_connectToTime`;
optionVar -iv "AL_usdmaya_ProxyShapeImport_unloaded" `checkBox -q -v AL_usdmaya_ProxyShapeImport_unloaded`;
};
global proc load_AL_usdmaya_ProxyShapeImport_optionGUI()
{
textField -e -tx "" AL_usdmaya_ProxyShapeImport_primPath;
textField -e -tx "" AL_usdmaya_ProxyShapeImport_excludePrimPath;
textField -e -tx "" AL_usdmaya_ProxyShapeImport_name;
checkBox -e -v `optionVar -q "AL_usdmaya_ProxyShapeImport_connectToTime"` AL_usdmaya_ProxyShapeImport_connectToTime;
checkBox -e -v `optionVar -q "AL_usdmaya_ProxyShapeImport_unloaded"` AL_usdmaya_ProxyShapeImport_unloaded;
};
global proc reset_AL_usdmaya_ProxyShapeImport_optionGUI()
{
textFieldButtonGrp -e -fi "" AL_usdmaya_ProxyShapeImport_file;
textField -e -tx "" AL_usdmaya_ProxyShapeImport_primPath;
textField -e -tx "" AL_usdmaya_ProxyShapeImport_excludePrimPath;
textField -e -tx "" AL_usdmaya_ProxyShapeImport_name;
checkBox -e -v 1 AL_usdmaya_ProxyShapeImport_connectToTime;
checkBox -e -v 0 AL_usdmaya_ProxyShapeImport_unloaded;
};
global proc execute_AL_usdmaya_ProxyShapeImport_optionGUI()
{
string $str = "AL_usdmaya_ProxyShapeImport ";
if(`textFieldButtonGrp -ex AL_usdmaya_ProxyShapeImport_file`)
if(!size(`textFieldButtonGrp -q -fi AL_usdmaya_ProxyShapeImport_file`)) {
error "File Path must be specified";
return;
}
if(`textField -ex AL_usdmaya_ProxyShapeImport_primPath`)
if(size(`textField -q -tx AL_usdmaya_ProxyShapeImport_primPath`))
$str += " -primPath \"" + `textField -q -tx AL_usdmaya_ProxyShapeImport_primPath` + "\"";
if(`textField -ex AL_usdmaya_ProxyShapeImport_excludePrimPath`)
if(size(`textField -q -tx AL_usdmaya_ProxyShapeImport_excludePrimPath`))
$str += " -excludePrimPath \"" + `textField -q -tx AL_usdmaya_ProxyShapeImport_excludePrimPath` + "\"";
if(`textField -ex AL_usdmaya_ProxyShapeImport_name`)
if(size(`textField -q -tx AL_usdmaya_ProxyShapeImport_name`))
$str += " -name \"" + `textField -q -tx AL_usdmaya_ProxyShapeImport_name` + "\"";
$str += " -file \"" + `textFieldButtonGrp -q -fi AL_usdmaya_ProxyShapeImport_file` + "\"";
$str += " -connectToTime " + `optionVar -q "AL_usdmaya_ProxyShapeImport_connectToTime"`;
$str += " -unloaded " + `optionVar -q "AL_usdmaya_ProxyShapeImport_unloaded"`;
eval $str;
};
global proc build_AL_usdmaya_ProxyShapeImport_labels()
{
text -al "right" -h 20 -w 160 -l "File Path:";
text -al "right" -h 20 -w 160 -l "USD Prim Path:";
text -al "right" -h 20 -w 160 -l "Exclude Prim Path:";
text -al "right" -h 20 -w 160 -l "Proxy Shape Node Name:";
text -al "right" -h 20 -w 160 -l "Connect to Time:";
text -al "right" -h 20 -w 160 -l "Opens the layer with payloads unloaded.:";
};
global proc build_AL_usdmaya_ProxyShapeImport_controls()
{
textFieldButtonGrp -h 20 -bl "..." -bc "alFileDialogHandler(\"USD Ascii (*.usd) (*.usd)\", \"AL_usdmaya_ProxyShapeImport_file\", 1)" AL_usdmaya_ProxyShapeImport_file;
textField -h 20 AL_usdmaya_ProxyShapeImport_primPath;
textField -h 20 AL_usdmaya_ProxyShapeImport_excludePrimPath;
textField -h 20 AL_usdmaya_ProxyShapeImport_name;
checkBox -l "" -h 20 AL_usdmaya_ProxyShapeImport_connectToTime;
checkBox -l "" -h 20 AL_usdmaya_ProxyShapeImport_unloaded;
};