Table of Contents

Links

Mel dev ref resource:

Mel scripting guide:

some tools to study:

Access Maya object and Maya object concepts

General Grammar

Mel with Maya objects

Note and Issues about Maya selection

  1. Maya does not store the vertex in selection order

locator and inform sampling

Common Mel Tool

system detection

File operation

modeling mel tool

//select mode
SelectVertexMask
SelectEdgeMask
SelectFacetMask
SelectToggleMode
 
updateLockSelectionIcon; // select lock
 
// display mode
ToggleBackfaceGeometry;
DisplayWireframe;
DisplayShaded;
ToggleFaceNormalDisplay;
 
ShowManipulatorTool;
 
//mirror x
 
//delete history
delete -ch;
 
// bevel plus for curves
bevelPlus -ch 1 -js 1 -tol 0.01 -ns 4 -cap 4 -width 0.1 -depth 0.1 -ed 0.5 -bevelInside 0 -outerStyle 2 -innerStyle 2 -polygon 1 -no 1 -polyOutMethod 2 -polyOutExtrusionType 3 -polyOutExtrusionSamples 2 -polyOutCurveType 3 -polyOutCurveSamples 6 -polyOutUseChordHeightRatio 0 `ls -sl`;
 
// rebuild with reduce for curves
rebuildCurve -ch 1 -rpo 1 -rt 1 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 4 -d 3 -tol 0.9 `ls -sl`;
Loop SplitEdgeRingTool
Brid performPolyBridgeEdge 0
Extr performPolyExtrude 0
Fill FillHole
Spli SplitPolygonTool
AveV performPolyAverageVertex 0
Cetr MergeToCenter
Save SaveScene
-0- setAttr \“testMat.transparency\” -type double3 1 1 1
-7- setAttr \“testMat.transparency\” -type double3 0.7 0.7 0.7
-%- setAttr \“testMat.transparency\” -type double3 0 0 0

scripting mel tool

material and hypershade mel tool

Rigging mel tool

animation mel tool

Expression linking and Rigging mel

// create a expression
expression -s "battery01.ty=batteryCover.rx/10.0*(-0.5);"  -o battery01 -n "expBattery01move" -ae 1 -uc all ;
 
// update a expression
expression -e -s "battery01.ty=batteryCover.rx/10.0*(-0.5);"  -o battery01 -ae 1 -uc all expBattery01move;
 
//delete a expression
delete expBattery01move;

camera mel tool

// pan image plane
// -down
 
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`;
float $verticalFilmOffset = `getAttr ($camera + ".verticalFilmOffset")`;
setAttr  ($camera+ ".verticalFilmOffset")  ($verticalFilmOffset - 0.02) ;
print ($camera + ".verticalFilmOffset = " +($verticalFilmOffset - 0.02) + "\n"); 
 
// -home
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`;
setAttr  ($camera + ".verticalFilmOffset") 0.0;
setAttr  ($camera +".horizontalFilmOffset") 0.0;
setAttr  ($camera + ".overscan")  1.0 ; 
 
// -in
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`; float $overscan =
`getAttr ($camera + ".overscan")`; setAttr  ($camera + ".overscan")
($overscan - 0.1) ; print ($camera + ".overscan = " + ($overscan - 0.1)  +
"\n");
 
// -left
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`;
float $horizontalFilmOffset = `getAttr ($camera + ".horizontalFilmOffset")`;
setAttr ($camera + ".horizontalFilmOffset")  ($horizontalFilmOffset - 0.02) ;
print ($camera +".horizontalFilmOffset = " + ($horizontalFilmOffset - 0.02)  + "\n"); 
 
// -out
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`; float $overscan =
`getAttr ($camera + ".overscan")`; setAttr  ($camera + ".overscan")
($overscan + 0.1) ; print ($camera + ".overscan = " + ($overscan + 0.1)  +
"\n"); 
 
// -right
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`;
float $horizontalFilmOffset = `getAttr ($camera + ".horizontalFilmOffset")`;
setAttr ($camera + ".horizontalFilmOffset")  ($horizontalFilmOffset + 0.02) ;
print ($camera +".horizontalFilmOffset = " + ($horizontalFilmOffset + 0.02)  + "\n"); 
 
// -up
string $currentPanel = `getPanel -up`;
string $camera = `modelPanel -q -camera $currentPanel`;
float $verticalFilmOffset = `getAttr ($camera + ".verticalFilmOffset")`;
setAttr  ($camera+ ".verticalFilmOffset")  ($verticalFilmOffset + 0.02) ;
print ($camera + ".verticalFilmOffset = " +($verticalFilmOffset + 0.02 ) + "\n"); 

window mel tool

Windows and Its UIs

// maya windows
ScriptEditor;
OutlinerWindow;
DisplayLayerEditorWindow;
toggleUIComponentVisibility "Channel Box / Layer Editor"
GraphEditor;
HypershadeWindow;
 
// render
PlayblastWindow;
RenderViewWindow;
unifiedRenderGlobalsWindow;
renderWindowRender redoPreviousRender renderView;
BatchRender;
 
// animation
toggleUIComponentVisibility "Time Slider";
toggleUIComponentVisibility "Range Slider";
PreferencesWindow;
SetProject; // set project window
file import; // import window
 
// layout
setNamedPanelLayout "Four View";
 
// advanced window
ReferenceEditor;
mentalrayApproxEditor;

HUD mel tool

maya preference setup

// APSC 1.5x crop DSLR (inch)
optionVar -floatValue cameraHorizAper 0.929;
optionVar -floatValue cameraVertAper 0.618;
 
// maya unit
optionVar -sv "workingUnitLinear" "cm" ;
 
// maya version
about -f
 
// getenv "varName"
 
// load maya rc file
if ( `filetest -r $myScriptFile` ) eval( "source \""+$myScriptFile+"\";" );
 
optionVar -sv "ViewImageDir" "xn_view";
optionVar -sv "ViewSequenceDir" "djv_view";
optionVar -sv "ViewImageCmdFormat" "%f %s-%e";
optionVar -sv "ViewSequenceCmdFormat" "%f %s-%e";

Maya GUI scripting

Maya UI interaction

basic UI elements

built-in UI manipulation

QT Gui for Maya 2011 and above

QT MEL
1-push Button (under Buttons group) button
2-radio button (under Buttons group) radioButton
3-check box(under Buttons group) checkBox
4-combo box (under containers group) optionMenu
5-line edit (under input widgets group) textField
6-spin box (under input widgets group)
7-double spine box (under input widgets group)
8-dial (under input widgets group)
9-list view (under item views model based) textScrollList
10-horizontal slider (under input widgets) intSlider
11-label (under display widgets group) text
12-progress bar (under display widgets group) progressBar
13-vertical slider (under input widgets) intSlider
14-horizontal line (under input widgets)
15-vertical line (under input widgets)
16-group box (under containers group)
17-tab widget (under container group) tabLayout
18-main window window

DIY Plugin related melscript

Mel ScriptJob and ScriptNode

I came across this when I was developing a rig system that requires how-condition-scripting and embeded script function for a on-server maya file.

Short difference is:

ScriptNode←—ScriptJob—→ScriptNode

Math in 3D

Common mel function lib

display func

general edit

select func

Rigging related function

Mesh-Joint weight map store and restore

// vtx
$selVtx=`ls -sl -fl`;
$countVtx=size($selVtx);
print ("vtx :"+$countVtx);
// bones
string $selJnt[]=`ls -sl`;
$countJnt=size($selJnt);
print ("jnt :"+$countJnt);
print $selJnt;
// matrix
string $declare = ( "matrix $wmap[" + $countJnt + "][" + $countVtx + "];" );
eval $declare;
// joint based store data
for ( $i = 0; $i < $countJnt ; $i++ ) {
    print ("now storing $selJnt["+$i+"] : "+$selJnt[$i]+"\n");
 
    for ( $j = 0; $j < $countVtx ; $j++ ) {
        $tmpW=`skinPercent -t $selJnt[$i] -q skinCluster1 $selVtx[$j]`;
        string $declare = ( "$wmap[" + $i + "][" + $j + "]="+$tmpW+";" );
        eval $declare;
    }
    print ("Finished storing $selJnt["+$i+"] : "+$selJnt[$i]+"\n");
}
 
// test query
skinPercent -t $selJnt[0] -q skinCluster1 $selVtx[0];
print $wmap[0][0];
// apply weight, name the targe joint as jointName+"new"
// skinPercent -tv joint1 0.2 skinCluster1 pPlane1.cv[100];
 
// vtx base re-assign
float $tmpWt;
$countJnt1=$countJnt-1;
// vtx base re-assign, manual turn off all the holding
for ( $i = 0; $i < $countJnt1 ; $i++ ){
    print ("now apply for $selJnt["+$i+"] : "+$selJnt[$i]+"\n");
    $newJnt=($selJnt[$i]+"new"); // new jnt naming convention
    for ( $j = 0; $j < $countVtx ; $j++ ) {
        string $declare = ( "$tmpWt=$wmap[" + $i + "][" + $j + "];" );
        eval $declare;
        skinPercent -tv $newJnt $tmpWt skinCluster1 $selVtx[$j];
    }
    print ("Finished for $selJnt["+$i+"] : "+$selJnt[$i]+"\n");
    // hold it
    setAttr ($newJnt+".liw")  1;
}
print $wmap;
// test query
skinPercent -t $selJnt[0] -q skinCluster1 $selVtx[0];

OS-System related function

open project folder in OS File Manager

// expanded based on http://oy-maya-scripts.googlecode.com
global proc shi_openProjectInExplorer()
{
// get the current project
string $projectRootPath = `workspace -q -rd`;
string $nativeProjectRootPath = toNativePath($projectRootPath);
string $systemCommand="";
if(`about -os` == "nt") string $systemCommand = "explorer /e,"+$nativeProjectRootPath;
if(`about -os` == "linux64") string $systemCommand = "konqueror "+$nativeProjectRootPath;
 
system ($systemCommand);
}

Custom UI creation function

custom menu creation

global proc myMenu()
{
global string $showMyMenuCtrl;
if (`menu -exists $showMyMenuCtrl`)
   deleteUI $showMyMenuCtrl;
string $name = "My Menu";
global string $gMainWindow;
$showMyMenuCtrl = `menu -p $gMainWindow -to true -l $name`;
menuItem -p $showMyMenuCtrl -l "Alpha" -c ("source \"alpha.mel\"; ");
menuItem -p $showMyMenuCtrl -l "Bravo" -c ("source \"bravo.mel\"; ");
menuItem -p $showMyMenuCtrl -l "Charlie" -c ("source \"charlie.mel\"; ");
};
myMenu;

Custom HUD creation

GUI mel for my own use

toolbox shiShelfTool
markingmenu mm_Sel_filter
menu vip_item_menu

shiShelfTool

A floating shelf with built-in functions and Realtime Strategy Game like Commanding icons.

mm_shi_sel_filter

mm_shi_sel_filter.mel
    menuItem
        -label "shiSelectPoly" 
        -command "setObjectPickMask \"All\" 0;selectType -polymesh 1;\n" 
        -radialPosition "N" 
        menuEditorMenuItem2;
 
    menuItem
        -label "shiSelectLocator" 
        -command "setObjectPickMask \"All\" 0;selectType -locator 1\n" 
        -radialPosition "NE" 
        menuEditorMenuItem8;
 
    menuItem
        -label "shiSelectCluster" 
        -command "setObjectPickMask \"All\" 0;selectType -cluster 1;\n" 
        -radialPosition "E" 
        menuEditorMenuItem4;
 
    menuItem
        -label "shiSelectLattice" 
        -command "setObjectPickMask \"All\" 0;selectType -lattice 1;\n" 
        -radialPosition "SE" 
        menuEditorMenuItem6;
 
    menuItem
        -label "shiSelectCurve" 
        -command "setObjectPickMask \"All\" 0;setObjectPickMask \"Curve\" 1;\n" 
        -radialPosition "S" 
        menuEditorMenuItem3;
 
    menuItem
        -label "shiSelectIK" 
        -command "setObjectPickMask \"All\" 0;selectType -ikHandle 1;\n" 
        -radialPosition "SW" 
        menuEditorMenuItem7;
 
    menuItem
        -label "shiSelectJoint" 
        -command "setObjectPickMask \"All\" 0;setObjectPickMask \"Joint\" true;\n" 
        -radialPosition "W" 
        -enableCommandRepeat 1
        menuEditorMenuItem5;
 
    menuItem
        -label "shiSelectDeformer" 
        -command "setObjectPickMask \"All\" 0;setObjectPickMask \"Deformer\" true;\n" 
        -radialPosition "NW" 
        menuEditorMenuItem9;
 
    menuItem
        -label "shiSelectLight" 
        -command "setObjectPickMask \"All\" 0;selectType -light 1;\n" 
        menuEditorMenuItem10;
 
    menuItem
        -label "shiSelectCam" 
        -command "setObjectPickMask \"All\" 0;selectType -camera 1;\n" 
        menuEditorMenuItem11;
 
    menuItem
        -divider 1
        menuEditorMenuItem12;
 
    menuItem
        -label "shiSelectMaskAll" 
        -command "setObjectPickMask \"All\" 1;\n" 
        menuEditorMenuItem13;
 
    menuItem
        -label "shiLockSelection" 
        -command "updateLockSelectionIcon;" 
        menuEditorMenuItem14;
 
setParent -m ..;

scripts for my own use

material color_bucket_gen mm_paint_list
modeling common_create cube_softify

ref creation

// ref: http://xyz2.net/mel/mel.103.htm
// usage: it create refPlane01, and refMat01, and load ref01.png under ref/ folder
// refPlane
polyPlane -ax 0 0 1 -w 10 -h 10 -sx 2 -sy 2 -n "refPlane01";
move -a 0 0 -5;
//refMat;
string $myRefMat = `shadingNode -asShader lambert -name "refMat01"`;
string $mySG = `sets -renderable true -noSurfaceShader true -empty -name "refMatSG01"`;
connectAttr -f ( $myRefMat + ".outColor" ) ( $mySG + ".surfaceShader" );
string $myFileNode = `shadingNode -asTexture file -name "refFile01"`;
connectAttr -f ( $myFileNode + ".outColor" ) ( $myRefMat + ".color" );
string $filepath = "ref/ref01.png";
setAttr -type "string" ( $myFileNode + ".fileTextureName" ) $filepath;
select refPlane01;
hyperShade -assign refMat01;
/* // link map png transparency
connectAttr -force refFile01.outTransparency refMat01.transparency;
*/

color bucket button set (Setup+UI)

// color bucket - create preset materials
// (red,blue,green,grey,white,black,yellow)
/*
color bucket
*/
global proc ccMatSetup()
{
string $myNewColor = `shadingNode -asShader lambert -name "ccRed"`;
setAttr -type double3 ( $myNewColor + ".color" ) 1 0 0;
string $myNewColor = `shadingNode -asShader lambert -name "ccGreen"`;
setAttr -type double3 ( $myNewColor + ".color" ) 0 1 0;
string $myNewColor = `shadingNode -asShader lambert -name "ccBlue"`;
setAttr -type double3 ( $myNewColor + ".color" ) 0 0 1;
string $myNewColor = `shadingNode -asShader lambert -name "ccWhite"`;
setAttr -type double3 ( $myNewColor + ".color" ) 1 1 1;
string $myNewColor = `shadingNode -asShader lambert -name "ccGrey"`;
setAttr -type double3 ( $myNewColor + ".color" ) 0.5 0.5 0.5;
string $myNewColor = `shadingNode -asShader lambert -name "ccBlack"`;
setAttr -type double3 ( $myNewColor + ".color" ) 0 0 0;
string $myNewColor = `shadingNode -asShader lambert -name "ccYellow"`;
setAttr -type double3 ( $myNewColor + ".color" ) 1 1 0;
}
/* please put this shelf button in your fav UI
shelfButton
-label "ccMat" 
-imageOverlayLabel "ccMat" 
-image "render_rampShader.xpm" 
-image1 "render_rampShader.xpm"
-style "iconOnly" 
-command "HypershadeWindow" 
-mi "ccRed" ("hyperShade -assign ccRed;")
-mi "ccGreen" ("hyperShade -assign ccGreen;")
-mi "ccBlue" ("hyperShade -assign ccBlue;")
-mi "ccWhite" ("hyperShade -assign ccWhite;")
-mi "ccGrey" ("hyperShade -assign ccGrey;")
-mi "ccBlack" ("hyperShade -assign ccBlack;")
-mi "ccYellow" ("hyperShade -assign ccYellow;")
-mi "-----------" ("")
-mi "-----------" ("")
-mi "ccMatSetup" ("ccMatSetup")
-sourceType "mel" 
-commandRepeatable 1
;
*/
mm_shi_cc_assign.mel
/* setup guide - total manual way in hotkey editor
// yourMM_press
if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
popupMenu -button 1 -ctl false -alt false -allowOptionBoxes true -parent viewPanes -mm 1 tempMM;
source "mm_shi_cc_assign.mel"; // only to change this
// yourMM_release
if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
*/
    menuItem -label "ccRed" -command "hyperShade -assign ccRed;" mmCCAmi_red;
    menuItem -label "ccGreen" -command "hyperShade -assign ccGreen;" mmCCAmi_green;
    menuItem -label "ccBlue" -command "hyperShade -assign ccBlue;" mmCCAmi_blue;
    menuItem -label "ccWhite" -command "hyperShade -assign ccWhite;" mmCCAmi_white;
    menuItem -label "ccGrey" -command "hyperShade -assign ccGrey;" mmCCAmi_grey;
    menuItem -label "ccBlack" -command "hyperShade -assign ccBlack;" mmCCAmi_black;
    menuItem -label "ccYellow" -command "hyperShade -assign ccYellow;" mmCCAmi_yellow;
    menuItem -label "---------" -command "" mmCCAmi_dash;
    menuItem -label "ccMatSetup" -command "ccMatSetup" mmCCAmi_ccMatSetup;
setParent -m ..;

Play with Cube

// title: random cube generator v0.1a
// usage: create random shaped cube
for($i=0;$i<10;$i++){
int $tmpVary=6;
int $tmpSize=10;
polyCube -w $tmpSize -h $tmpSize -d $tmpSize -cuv 4;
string $selected[]=`ls -sl`;
$tmpCube=$selected[0];
//move -5 -5 -5 ($tmpCube+".scalePivot") ($tmpCube+".rotatePivot") ;
move (50) (0+15*$i) 0;
 
$tmpP1=floor(rand(0,2));
$tmpP2=floor(rand(3,5));
$tmpP3=floor(rand(6,7));
select -r $tmpCube.vtx[$tmpP1] ;
move -r (rand($tmpVary)) (rand($tmpVary)) (rand($tmpVary));
select -r $tmpCube.vtx[$tmpP2] ;
move -r (rand($tmpVary)) (rand($tmpVary)) (rand($tmpVary));
select -r $tmpCube.vtx[$tmpP3] ;
move -r (rand($tmpVary)) (rand($tmpVary)) (rand($tmpVary));
}
select -cl;
// selected cubic soft edge script - v0.1
// shining 2011 mar
// able to handle multi cube selection, no cube as tmpCube
 
string $selected[] = `ls -sl`;
 
for ($selectedItem in $selected) { //loop 1 starts
rename $selectedItem "tmpCube" ;
// find rough size
$tmpSizeValue=`polyEvaluate -boundingBox tmpCube`;
float $tmpSizeValueX = ($tmpSizeValue[1]-$tmpSizeValue[0]);
float $tmpSizeValueY = ($tmpSizeValue[3]-$tmpSizeValue[2]);
float $tmpSizeValueZ = ($tmpSizeValue[5]-$tmpSizeValue[4]);
float $tmpCubeValue=0.1*min($tmpSizeValueX,min($tmpSizeValueY,$tmpSizeValueZ));
// scale in cube
move -r 0 ($tmpCubeValue) 0 tmpCube.vtx[0:1] tmpCube.vtx[6:7];
move -r 0 (-1*$tmpCubeValue) 0 tmpCube.vtx[2:5];
move -r 0 0 (-1*$tmpCubeValue) tmpCube.vtx[0:3];
move -r 0 0 ($tmpCubeValue) tmpCube.vtx[4:7];
move -r (-1*$tmpCubeValue) 0 0 tmpCube.vtx[1] tmpCube.vtx[3] tmpCube.vtx[5] tmpCube.vtx[7];
move -r ($tmpCubeValue) 0 0 tmpCube.vtx[0] tmpCube.vtx[2] tmpCube.vtx[4] tmpCube.vtx[6];
// extrube back cube
polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -divisions 1 -twist 0 -taper 1 -off 0 -lt 0 0 ($tmpCubeValue) -smoothingAngle 30 tmpCube.f[0] tmpCube.f[2];
polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -divisions 1 -twist 0 -taper 1 -off 0 -lt 0 0 ($tmpCubeValue) -smoothingAngle 30 tmpCube.f[4] tmpCube.f[5] tmpCube.f[7] tmpCube.f[9] tmpCube.f[11] tmpCube.f[13];
polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -divisions 1 -twist 0 -taper 1 -off 0 -lt 0 0 ($tmpCubeValue) -smoothingAngle 30 tmpCube.f[1] tmpCube.f[3] tmpCube.f[6] tmpCube.f[8] tmpCube.f[10] tmpCube.f[12] tmpCube.f[14:16] tmpCube.f[18:19] tmpCube.f[21:24] tmpCube.f[26:27] tmpCube.f[29];
polySmooth  -mth 0 -dv 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 tmpCube;
polyDelEdge -cv true -ch 1 tmpCube.e[216:240] tmpCube.e[242] tmpCube.e[244] tmpCube.e[246] tmpCube.e[248] tmpCube.e[250] tmpCube.e[252] tmpCube.e[254] tmpCube.e[256] tmpCube.e[258] tmpCube.e[260] tmpCube.e[262] tmpCube.e[264] tmpCube.e[266] tmpCube.e[268] tmpCube.e[270] tmpCube.e[272] tmpCube.e[274] tmpCube.e[276] tmpCube.e[278] tmpCube.e[284] tmpCube.e[286] tmpCube.e[296] tmpCube.e[298] tmpCube.e[304] tmpCube.e[306] tmpCube.e[308] tmpCube.e[310] tmpCube.e[316] tmpCube.e[318] tmpCube.e[328] tmpCube.e[330] tmpCube.e[336] tmpCube.e[338] tmpCube.e[340] tmpCube.e[342] tmpCube.e[344] tmpCube.e[346] tmpCube.e[364] tmpCube.e[366] tmpCube.e[384] tmpCube.e[386] tmpCube.e[388] tmpCube.e[390] tmpCube.e[392] tmpCube.e[394] tmpCube.e[412] tmpCube.e[414];
rename tmpCube $selectedItem ;
} 
//loop 1 ends

Portable hotkey

Mel hotkey initialize sequence

  1. userRunTimeCommands.mel (defining a mel script into alisa name)
  2. userNamedCommands.mel (give a link name to each alias command)
  3. userHotkeys.mel (assign keystroke to each link)

Runtime command vs Name command

Example of NameCommand-only way of shortcut

require “shi_fun.mel” load first for my personal cmds;

//-----------------------modeling
nameCommand -ann "NC_shiToggleMode_1" -c ("shiToggleMode(1)") NC_shiToggleMode_1;
hotkey -k "1" -ctl -n ("NC_shiToggleMode_1");
 
nameCommand -ann "NC_shiToggleMode_2" -c ("shiToggleMode(2)") NC_shiToggleMode_2;
hotkey -k "2" -ctl -n ("NC_shiToggleMode_2");
 
nameCommand -ann "NC_shiToggleMode_3" -c ("shiToggleMode(3)") NC_shiToggleMode_3;
hotkey -k "3" -ctl -n ("NC_shiToggleMode_3");
 
//------------------------ view port
nameCommand -ann "NC_view_tWireframe" -c ("shiToggleWireOnShade") NC_view_tWireframe;
hotkey -k "f" -ctl -alt -n ("NC_view_tWireframe");
 
//------------------------ windows
 
// outliner
nameCommand -ann "NC_win_outliner" -c ("if (`window -ex outlinerPanel1Window`) deleteUI outlinerPanel1Window;else OutlinerWindow;") NC_win_outliner;
hotkey -k "4" -ctl -n ("NC_win_outliner");
 
// script editor
nameCommand -ann "NC_win_scriptEditor" -c ("if (`window -ex scriptEditorPanel1Window`) deleteUI scriptEditorPanel1Window;else ScriptEditor;") NC_win_scriptEditor;
hotkey -k "x" -ctl -alt -n ("NC_win_scriptEditor");
 
// hyperShade
nameCommand -ann "NC_win_hyperShade" -c ("if (`window -ex hyperShadePanel1Window`) deleteUI hyperShadePanel1Window;else HypershadeWindow") NC_win_hyperShade;
hotkey -k "s" -ctl -alt -n ("NC_win_hyperShade");
 
// graph editor
nameCommand -ann "NC_win_graphEditor" -c ("if (`window -ex graphEditor1Window`) deleteUI graphEditor1Window;else GraphEditor") NC_win_graphEditor;
hotkey -k "g" -ctl -alt -n ("NC_win_graphEditor");
 
//------------------------ redo
nameCommand -ann "NC_fun01" -c ("fun01") NC_fun01;
hotkey -k "d" -ctl -alt -n ("NC_fun01");

Example of RunTimeCommand NameCommand way of shortcut

require “shi_fun.mel” load first for my personal cmds;

runtime cmd

//Maya Preference 2010 (Release 1)
//
//
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`;\nfloat $horizontalFilmOffset = `getAttr ($camera + \".horizontalFilmOffset\")`;\nsetAttr ($camera + \".horizontalFilmOffset\")  ($horizontalFilmOffset + 0.02) ;\nprint ($camera +\".horizontalFilmOffset = \" + ($horizontalFilmOffset + 0.02)  + \"\\n\"); ")
	camRight;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`;\nfloat $horizontalFilmOffset = `getAttr ($camera + \".horizontalFilmOffset\")`;\nsetAttr ($camera + \".horizontalFilmOffset\")  ($horizontalFilmOffset - 0.02) ;\nprint ($camera +\".horizontalFilmOffset = \" + ($horizontalFilmOffset - 0.02)  + \"\\n\"); ")
	camLeft;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`;\nfloat $verticalFilmOffset = `getAttr ($camera + \".verticalFilmOffset\")`;\nsetAttr  ($camera+ \".verticalFilmOffset\")  ($verticalFilmOffset + 0.02) ;\nprint ($camera + \".verticalFilmOffset = \" +($verticalFilmOffset + 0.02 ) + \"\\n\"); ")
	camUp;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`;\nfloat $verticalFilmOffset = `getAttr ($camera + \".verticalFilmOffset\")`;\nsetAttr  ($camera+ \".verticalFilmOffset\")  ($verticalFilmOffset - 0.02) ;\nprint ($camera + \".verticalFilmOffset = \" +($verticalFilmOffset - 0.02) + \"\\n\"); ")
	camDown;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`;\nsetAttr  ($camera + \".verticalFilmOffset\") 0.0;\nsetAttr  ($camera +\".horizontalFilmOffset\") 0.0;\nsetAttr  ($camera + \".overscan\")  1.0 ; ")
	camHome;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`; float $overscan =\n`getAttr ($camera + \".overscan\")`; setAttr  ($camera + \".overscan\")\n($overscan - 0.1) ; print ($camera + \".overscan = \" + ($overscan - 0.1)  +\n\"\\n\");\n")
	camIn;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("string $currentPanel = `getPanel -up`;\nstring $camera = `modelPanel -q -camera $currentPanel`; float $overscan =\n`getAttr ($camera + \".overscan\")`; setAttr  ($camera + \".overscan\")\n($overscan + 0.1) ; print ($camera + \".overscan = \" + ($overscan + 0.1)  +\n\"\\n\"); ")
	camOut;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("shiRename")
	shiRenameCmd;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("srcTool")
	myToolWindow;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("GraphEditor")
	winGraphEditor;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("HotkeyPreferencesWindow;")
	winHotkeyEditor;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("HypershadeWindow;")
	winHyperShade;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("shiToggleWireOnShade")
	act_toggle_wire_on_shade;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("OutlinerWindow;")
	winOutliner;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("ScriptEditor;")
	winScriptEditor;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("srcShelf")
	win_shiShelfTool;
 
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("dnMePan")
	cam_PanTool;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("OutlinerWindow")
	win_outliner;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("shiToggleMode(1)")
	fun_shiToggleMode_1;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("shiToggleMode(2)")
	fun_shiToggleMode_2;
 
runTimeCommand
	-annotation ""
	-category "User"
	-commandLanguage "mel"
	-command ("shiToggleMode(3)")
	fun_shiToggleMode_3;

name cmd

//Maya Preference 2010 (Release 1)
//
//
 
nameCommand
	-annotation "camRightNameCommand"
	-sourceType "mel"
	-command ("camRight")
	camRightNameCommand;
 
nameCommand
	-annotation "camLeftNameCommand"
	-sourceType "mel"
	-command ("camLeft")
	camLeftNameCommand;
 
nameCommand
	-annotation "camUpNameCommand"
	-sourceType "mel"
	-command ("camUp")
	camUpNameCommand;
 
nameCommand
	-annotation "camDownNameCommand"
	-sourceType "mel"
	-command ("camDown")
	camDownNameCommand;
 
nameCommand
	-annotation "camHomeNameCommand"
	-sourceType "mel"
	-command ("camHome")
	camHomeNameCommand;
 
nameCommand
	-annotation "camInNameCommand"
	-sourceType "mel"
	-command ("camIn")
	camInNameCommand;
 
nameCommand
	-annotation "camOutNameCommand"
	-sourceType "mel"
	-command ("camOut")
	camOutNameCommand;
 
nameCommand
	-annotation "shiRenameCmdNameCommand"
	-sourceType "mel"
	-command ("shiRenameCmd")
	shiRenameCmdNameCommand;
 
nameCommand
	-annotation "myToolWindowNameCommand"
	-sourceType "mel"
	-command ("myToolWindow")
	myToolWindowNameCommand;
 
nameCommand
	-annotation "winGraphEditorNameCommand"
	-sourceType "mel"
	-command ("winGraphEditor")
	winGraphEditorNameCommand;
 
nameCommand
	-annotation "winHotkeyEditorNameCommand"
	-sourceType "mel"
	-command ("winHotkeyEditor")
	winHotkeyEditorNameCommand;
 
nameCommand
	-annotation "winHyperShadeNameCommand"
	-sourceType "mel"
	-command ("winHyperShade")
	winHyperShadeNameCommand;
 
nameCommand
	-annotation "act_toggle_wire_on_shadeNameCommand"
	-sourceType "mel"
	-command ("act_toggle_wire_on_shade")
	act_toggle_wire_on_shadeNameCommand;
 
nameCommand
	-annotation "winOutlinerNameCommand"
	-sourceType "mel"
	-command ("winOutliner")
	winOutlinerNameCommand;
 
nameCommand
	-annotation "winScriptEditorNameCommand"
	-sourceType "mel"
	-command ("winScriptEditor")
	winScriptEditorNameCommand;
 
 
nameCommand
	-annotation "win_shiShelfToolNameCommand"
	-sourceType "mel"
	-command ("win_shiShelfTool")
	win_shiShelfToolNameCommand;
 
 
nameCommand
	-annotation "cam_PanToolNameCommand"
	-sourceType "mel"
	-command ("cam_PanTool")
	cam_PanToolNameCommand;
 
nameCommand
	-annotation "win_outlinerNameCommand"
	-sourceType "mel"
	-command ("win_outliner")
	win_outlinerNameCommand;
 
nameCommand
	-annotation "fun_shiToggleMode_1NameCommand"
	-sourceType "mel"
	-command ("fun_shiToggleMode_1")
	fun_shiToggleMode_1NameCommand;
 
nameCommand
	-annotation "fun_shiToggleMode_2NameCommand"
	-sourceType "mel"
	-command ("fun_shiToggleMode_2")
	fun_shiToggleMode_2NameCommand;
 
nameCommand
	-annotation "fun_shiToggleMode_3NameCommand"
	-sourceType "mel"
	-command ("fun_shiToggleMode_3")
	fun_shiToggleMode_3NameCommand;

hotkey binding

//Maya Preference 2010 (Release 1)
//
//
hotkey -keyShortcut "e" -ctl -name ("cam_PanToolNameCommand");
 
hotkey -keyShortcut "4" -ctl -name ("win_outlinerNameCommand");
hotkey -keyShortcut "1" -ctl -name ("fun_shiToggleMode_1NameCommand");
hotkey -keyShortcut "2" -ctl -name ("fun_shiToggleMode_2NameCommand");
hotkey -keyShortcut "3" -ctl -name ("fun_shiToggleMode_3NameCommand");
 
hotkey -keyShortcut "Right" -ctl -name ("camRightNameCommand");
hotkey -keyShortcut "Left" -ctl -name ("camLeftNameCommand");
hotkey -keyShortcut "Up" -ctl -name ("camUpNameCommand");
hotkey -keyShortcut "Down" -ctl -name ("camDownNameCommand");
hotkey -keyShortcut "Home" -name ("camHomeNameCommand");
hotkey -keyShortcut "Page_Up" -name ("camInNameCommand");
hotkey -keyShortcut "Page_Down" -name ("camOutNameCommand");
 
hotkey -keyShortcut "r" -ctl -name ("shiRenameCmdNameCommand");
 
hotkey -keyShortcut "w" -ctl -alt -name ("myToolWindowNameCommand");
hotkey -keyShortcut "r" -ctl -alt -name ("win_shiShelfToolNameCommand");
 
hotkey -keyShortcut "g" -ctl -alt -name ("winGraphEditorNameCommand");
hotkey -keyShortcut "h" -ctl -alt -name ("winHotkeyEditorNameCommand");
hotkey -keyShortcut "s" -ctl -alt -name ("winHyperShadeNameCommand");
hotkey -keyShortcut "x" -ctl -alt -name ("winHotkeyEditorNameCommand");
hotkey -keyShortcut "a" -ctl -alt -name ("winScriptEditorNameCommand");
 
hotkey -keyShortcut "f" -ctl -alt -name ("act_toggle_wire_on_shadeNameCommand");