CS838
Web

Home

Calendar

Syllabus

Reader

Assigns

Proj 1

Proj 2

Proj 3

maya plugin info

Getting Started Writing Scripts and Plugins for Maya

Alex Mohr, March 2002


Maya has two commonly used extension mechanisms -- MEL scripting and C++ Plugins. Both are targeted at different goals.

MEL

MEL is Maya's scripting language. MEL scripts are often used to perform common tasks that are accomplished by executing a series of Maya commands. (Maya commands are executed almost every time you use a menu, for instance.) MEL is also often used as the "glue" code in a project. That is, it is used to get different subsystems to operate together. For example, you might write a MEL script to get information out of Maya and translated to a format that your program understands. MEL has a set of reasonably powerful commands at its disposal and so may be used to implement more complex behavior too.

There are several different sources for learning about MEL. A good place to start is with Maya's documentation. There is a good introduction to MEL here (UW CS only). Also, once you're writing scripts, the MEL Command Reference will also be very useful (UW CS only). Please note that these two pages are direct links to the documentation available to you in Maya when you press "F1".

While you are running Maya, you may enter single MEL commands in the white text input bar below the left side of the time slider as shown below.



A more useful tool is the Script Editor which may be invoked by clicking the button highlighted in this image:



The Script Editor allows you to load and execute scripts, as its name suggests. However, it has one really great non-obvious feature. When trying to write your own MEL script, you will likely find yourself in a situation where you know how to accomplish something manually in Maya but don't know how to do it in MEL. One simple way to do this is to use the Script Editor to look at what commands Maya is executing. For example, open the Script Editor and then click on the sphere button to create a sphere in your scene. A line that looks like:

sphere -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -nsp 4 -ch 1;objectMoveCommand;

should have appeared in the script editor. This is exactly the MEL command sequence used to create that sphere. Unfortunately, every single command is not echoed to the Script Editor by default. In order to do that, you can select Edit->Echo All Commands in the Script Editor's menu bar. This causes Maya to be much more verbose. Try it with some commonly used features and you'll see the difference.



Plugins

Maya has a plugin architecture that is very powerful. It provides a C++ interface to much of Maya's functionality and data structures. Maya plugins are meant to be used for adding significant functionality to Maya, or when the operation of the extension must be fast.

Maya's documentation is the best place to look for learning to write plugins. Good information is available here (UW CS only). The only technical difficulty is how to set up a project in Visual Studio with all the right parameters.

If you do not want to set things up correctly yourself, you may use this example project as a base to get started from. It has correct settings for working in the CS labs. This plugin simply creates a nurbs helix when the user executes the MEL command "helloWorld". This is very similar to one of the first examples in the documentation and is just meant to get you started.

If you want to set up a project on your own, it is not difficult, just tedious. This page can help you with that. Please note that the AFS path to Maya is S:\maya-3.0\i386_win2k\.

If you get unresolved externals while linking, you may need to tell Visual Studio to link with the appropriate Maya libraries located in S:\maya-3.0\i386_win2k\lib.

Once you have your plugin compiling successfully you should have a file named plugin.mll where 'plugin' is the name of your plugin. To load your plugin in Maya follow these steps. Open the Plugin Manager by selecting Window->Settings/Preferences->Plug-in Manager. That will open a window that looks like this:



Click on the "Browse" button in the window and select your plugin. Maya should then load this plugin. Scrolling to the bottom of the Plug-in Manager, you should see something like this:



That is, your plugin should show up under "Other Registered Plugins". If it does not there may have been a problem in loading it. Check the script editor. To unload your plugin, simply uncheck the "loaded" checkbox. You must do this before you recompile your plugin and then reload it after you have recompiled it (by simply checking the checkbox).

Finally, while working on your project, you may become frustrated in trying to accomplish something. There are some online resources that may be of interest to you. Many can be found by searching on Google. One of the best ones is Highend 3D (www.highend3d.com). Be sure to check out their online Maya development forums -- especially if you are really stuck on a MEL problem.
CS838
website (c) 2002, Michael L. Gleicher