Mel Scripting a Joint Selection UI Tool in Maya
Below is the breakdown of the script used in the video.
//Defining our procedure, and its’ command name//
global proc JointSelectionTool_GUI ()
{//Declaring that if the JointSelectionTool_GUI window is currently open, to close it, and open a new one//
if(`window -exists JointSelectionTool_GUI`)
deleteUI JointSelectionTool_GUI;//Declaring our window, and defining its’ properties//
string $window = `window -title “Joint_Selecton_Tool” -widthHeight 400 400 JointSelectionTool_GUI`;
//Declaring our form, and telling maya that our form has a certain number of positions to attach an edge along the window, basically at 100 divisions, it acts as a percentage//
string $form = `formLayout -numberOfDivisions 100`;
string $jointSelect_text = `text -label “Select a group of joints from the drop down menu”`;//Declaring our drop down menu, and defining the different options to select from, and to call the command of the selected option//
string $selectJointGroup = `optionMenu -label “JointGroups” -changeCommand “#1″`;
menuItem -label “Select…”;
menuItem -label “LeftHandFingers”;
menuItem -label “RightHandFingers”;
menuItem -label “LeftIndexFinger”;
menuItem -label “RightIndexFinger”;//Declaring and defining our buttons and the commands they call when activated//
string $selectAllJointsButton = `button -label “Select All Joints” -command “SelectAllJoints”`;
string $restoreBindPose = `button -label “Restore Skeleton to Bind Pose” -command “dagPose -restore -global -bindPose”`;
string $evaluateAllButton = `button -label “Evaluate All Expressions” -command “EnableAll”`;
string $disableAllButton = `button -label “Disable/Ignore All Expressions” -command “DisableAll”`;
string $attrSelect_text = `text -label “Select the attribute to modify”`;
string $endOfTheWorldButton= `button -label “Pressing This Button Will Cause the End of the World… I Dare You” -backgroundColor 1.0 0.25 0.25 -command “endOfTheWorld”`;//Declaring and defining our joint groups to be affected//
string $LeftHandFingers[] = {“LeftHandIndex1″, “LeftHandIndex2″, “LeftHandMiddle1″, “LeftHandMiddle2″, “LeftHandRing1″, “LeftHandRing2″, “LeftHandPinky1″,
“LeftHandPinky2″, “LeftHandThumb1″, “LeftHandThumb2″, “LeftHandThumb3″};
string $RightHandFingers[] = {“RightHandIndex1″, “RightHandIndex2″, “RightHandMiddle1″, “RightHandMiddle2″, “RightHandRing1″, “RightHandRing2″, “RightHandPinky1″,
“RightHandPinky2″, “RightHandThumb1″, “RightHandThumb2″, “RightHandThumb3″};
string $LeftIndexFinger[] = {“LeftHandIndex1″, “LeftHandIndex2″};
string $RightIndexFinger[] = {“RightHandIndex1″, “RightHandIndex2″};//Declaring and defining our slider controls, specifically the selected attributes they control and the slider properties//
string $sliderLeftHand = `attrFieldSliderGrp -label “LeftHandRotateY” -attribute ($LeftHandFingers[0]+”.rotateY”) -fieldMinValue -90 -fieldMaxValue 90 -sliderMinValue -90 -sliderMaxValue 90 -minValue -360 -maxValue 360 -precision 3`;
string $sliderRightHand = `attrFieldSliderGrp -label “RightHandRotateY” -attribute ($RightHandFingers[0]+”.rotateY”) -fieldMinValue -90 -fieldMaxValue 90 -sliderMinValue -90 -sliderMaxValue 90 -minValue -360 -maxValue 360 -precision 3`;
string $sliderLeftHandIndex = `attrFieldSliderGrp -label “LeftHandIndexRotateY” -attribute ($LeftIndexFinger[0]+”.rotateY”) -fieldMinValue -90 -fieldMaxValue 90 -sliderMinValue -90 -sliderMaxValue 90 -minValue -360 -maxValue 360 -precision 3`;
string $sliderRightHandIndex = `attrFieldSliderGrp -label “RightHandIndexRotateY” -attribute ($RightIndexFinger[0]+”.rotateY”) -fieldMinValue -90 -fieldMaxValue 90 -sliderMinValue -90 -sliderMaxValue 90 -minValue -360 -maxValue 360 -precision 3`;//Defining our form, specifically the “top, bottom, left, and right” positions of various pre-definied functions, text, buttons, and sliders//
formLayout -edit
//The “-attachForm” flag tells maya its’ position based on the selected side of the form, the “-attachPosition” flag tells maya its’ position according to the number of divisions as either a defined distance, or percentage//
//In this section of the form, “$jointSelect_text” is aligned to the top of the window, and extends down 8% of the windows’ height, its’ left edge is positioned 2% from the left side of the window, and extends right to the edge of the window//
-attachForm $jointSelect_text “top” 0
-attachPosition $jointSelect_text “bottom” 0 8
-attachPosition $jointSelect_text “left” 0 2
-attachPosition $jointSelect_text “right” 0 100//In this section of the form, the top left corner of the “$selectJointGroup” drop down menu is positioned 8% down from the top and 2% from the left edge of the window, it extends down another 8% in length, totalling 16% from the top of the window, and extends right to the edge of the window//
-attachPosition $selectJointGroup “top” 0 8
-attachPosition $selectJointGroup “bottom” 0 16
-attachPosition $selectJointGroup “left” 0 2
-attachPosition $selectJointGroup “right” 0 98//In this section of the form, the “$selectAllJointsButton” starts down 16% from the top of the window, extends down further to 25% of the windows height, its’ left edge is aligned with the windows left side, and extends to the center of the windows total width//
-attachPosition $selectAllJointsButton “top” 0 16
-attachPosition $selectAllJointsButton “bottom” 0 25
-attachPosition $selectAllJointsButton “left” 0 0
-attachPosition $selectAllJointsButton “right” 0 50//By now, you should be seeing where this is going, for this section, the “$restoreBindPose” button starts 16% down from the top of the window, and extends down further to 25% of the windows height, its’ left edge starts in the centre of the windows width, and extends right to the edge of the window//
-attachPosition $restoreBindPose “top” 0 16
-attachPosition $restoreBindPose “bottom” 0 25
-attachPosition $restoreBindPose “left” 0 50
-attachPosition $restoreBindPose “right” 0 100-attachPosition $evaluateAllButton “top” 0 25
-attachPosition $evaluateAllButton “bottom” 0 35
-attachPosition $evaluateAllButton “left” 0 0
-attachPosition $evaluateAllButton “right” 0 50-attachPosition $disableAllButton “top” 0 25
-attachPosition $disableAllButton “bottom” 0 35
-attachPosition $disableAllButton “left” 0 50
-attachPosition $disableAllButton “right” 0 100-attachPosition $attrSelect_text “top” 0 35
-attachPosition $attrSelect_text “bottom” 0 43
-attachPosition $attrSelect_text “left” 0 2
-attachPosition $attrSelect_text “right” 0 98-attachPosition $sliderLeftHand “top” 0 43
-attachPosition $sliderLeftHand “bottom” 0 48
-attachPosition $sliderLeftHand “left” 0 0
-attachPosition $sliderLeftHand “right” 0 100-attachPosition $sliderRightHand “top” 0 48
-attachPosition $sliderRightHand “bottom” 0 53
-attachPosition $sliderRightHand “left” 0 0
-attachPosition $sliderRightHand “right” 0 100-attachPosition $sliderLeftHandIndex “top” 0 53
-attachPosition $sliderLeftHandIndex “bottom” 0 58
-attachPosition $sliderLeftHandIndex “left” 0 0
-attachPosition $sliderLeftHandIndex “right” 0 100-attachPosition $sliderRightHandIndex “top” 0 58
-attachPosition $sliderRightHandIndex “bottom” 0 63
-attachPosition $sliderRightHandIndex “left” 0 0
-attachPosition $sliderRightHandIndex “right” 0 100-attachPosition $endOfTheWorldButton “top” 0 63
-attachPosition $endOfTheWorldButton “bottom” 0 100
-attachPosition $endOfTheWorldButton “left” 0 0
-attachPosition $endOfTheWorldButton “right” 0 100//Calling the form, ensuring that the window will be correctly displayed, then calling the window//
$form;
window -edit -widthHeight 400 400 JointSelectionTool_GUI;
showWindow $window;
}//Defining our joint selection groups, and any other functions or procedures//
global proc LeftHandFingers ()
{
select -r LeftHandIndex1 LeftHandIndex2 LeftHandMiddle1 LeftHandMiddle2 LeftHandRing1 LeftHandRing2 LeftHandPinky1 LeftHandPinky2 LeftHandThumb1 LeftHandThumb2 LeftHandThumb3;
}global proc RightHandFingers ()
{
select -r RightHandIndex1 RightHandIndex2 RightHandMiddle1 RightHandMiddle2 RightHandRing1 RightHandRing2 RightHandPinky1 RightHandPinky2 RightHandThumb1 RightHandThumb2 RightHandThumb3;
}global proc LeftIndexFinger ()
{
select -r LeftHandIndex1 LeftHandIndex2;
}global proc RightIndexFinger ()
{
select -r RightHandIndex1 RightHandIndex2;
}global proc endOfTheWorld ()
{
confirmDialog -title “WARNING!!! End of the World…?” -message “… I guess I could put a little bit more effort into this right?” -button “Yes… Yes you can.”;
}//Calling the procedure to ensure the procedure activates, and finalizing the function//
JointSelectionTool_GUI;