Create a custom MEL shelf in Maya
Taking the time to learn mel gets easier if you let mel help you. Keep organized for long-time lessons by stocking your own custom shelf for mel scripts in Maya. Setting this up is super easy. First let's add the shelf in Maya. In the file menu go to Window > Settings/Preferences > Shelves. This opens the shelf editor. Existing shelves are listed and you can edit those here. But we need a new shelf to show up for our mel scripts. Choose the New Shelf button in the Shelves edit window. Name your shelf, it is create automatically. I named mine Beta, for my Beta versions of mel files. When i release a script for final use, i move it to a different shelf.
Now that we have our custom shelf set up, let's add some helpful mel commands to get going. First the easy ones. Since we are working with mel, why not a button to open the ScriptEditor. Easy enough, first (ironically) open the ScriptEditor:). You probably already know that in your File menu Window > General Editors > ScriptEditor will open the script editor. But did you also know you can just type ScriptEditor; into the mel command window and hit return? With the ScriptEditor open, type into the editor's lower window what is in quotes "ScriptEditor;". Open the new shelf you just made earlier so it is on top. This new shelf is empty. With the "ScriptEditor;" syntax highlighted in your editor, in the Script Editor dialog, choose the File > Save Selected to Shelf... option. It asks you for a new type, MEL Edit or something better. Click OK and you have a new button in your custom shelf. Clicking on the new button will open the Script Editor. You won't know this though because the Script Editor is open. Close the Script Editor, then try out your new button, the Script Editor will open.
Sorry for the side note, but here it goes. I knew to type in ScriptEditor; not by RTFM but instead by choosing the Echo All Commands option in the Script Editor dialog window (Under Script). With Echo selected, i went to the File menu and opened the Script Editor like everybody does. I was able to see the command "ScriptEditor;" in my echo output which tells me that's the command i need to open the Script Editor.
Now we can add our beta mel script button. This is your working button. It is designed so that you can simple edit the script in your favorite text editor and execute in Maya. In saves you a lot of trouble remembering to type source file and all that jazz. Firstly, create your mel file. Call the new script file "beta.mel" and place it in your maya/scripts/ folder. To get us started we will just use a simple one liner script for our beta.mel file.
//My Maya Beta MEL script
polyCube;
scale 1 2 1;
Once this is saved in your Maya scripts folder, restart Maya and open your Script Editor (hey, use your new button you jsut made above). In the Script Editor dialog window, choose File > "Source Script". Select the new beta.mel file you just made. A new shape will appear on your stage because we just ran the script "beta.mel". We did this so we could make sure our script works, and also so we can add it to your Beta Shelf. In your Script Editor dialog, look for the words in single quotes 'source "beta.mel";'. Highlight this and drag the highlighted text (yup) to the new Beta shelf next the the ScriptEditor open button you just made. When you let go, a new button is made in your shelf just like the first button. The only difference is how we dragged it to the shelf, and that it has no name (dragging text like this will omit the new name dialog). You can fix this by editing your shelves and renaming the button to Beta. Do this now so you won't get confused. While in the shelf editor you can also give it a custom icon since you will be looking at this button for quite a while in your Maya future :).
Remember, you dragged the command "source -FILE" to this new button. The source will always check for the newest version for you. This means you have just created a completely fluid mel working environment. You can check this by going back to your text editor and editing the beta.mel file to the following:
//My Updated Maya Beta MEL script
polyCube;
scale 1 1 1;
Switch back to Maya and hit the button again. The new changes are already in place and you do not need your Script Editor open anymore. Cheers to Maya for some great custom features like this one.
|