Complete Maya Programming Companion Files

The companion files include all the source code for the plugin and MEL examples. The subdirectories are as follows:

Directory

Contents

\Plugins

The source code (.cpp, .h) and Microsoft Visual C++ project files (.dsw) for all the example plugins

\Scenes

All the example Maya scenes (.ma)

\MEL Scripts

All the MEL scripts(.mel)

 


Compiling Example Plugins

Windows | Linux

Follow the instructions below to compile the example plugins.

Windows

Minimum Requirements:

Once you have setup the minimum requirements above you can compile and run the example plugins.

  1. Go to the subdirectory of the plugin you want to compile, e.g. \Plugins\BasicLocator
  2. Double-click on the project workspace file. This is the file with the .dsw extension, e.g. BasicLocator.dsw

    Visual C++ will load the project and show the plugin source code files.

  3. To build (compile and link) the plugin press F7 or select Build | Build pluginname.mll from the main menu.

    It is most likely the plugin won't compile. A list of compiler errors will be displayed in the output window. These will include:

    ... Cannot open include file: 'filename.h': No such file or directory

    This means that Visual C++ can't find one or more Maya include (.h) files.

  4. Press Alt+F7 or select Project | Settings... from the main menu.
  5. Click on the C++ tab.
  6. Click on the combo-box next to Category:
  7. Select Preprocessor from the drop-down list.

    The Additional include directories: box will contain a list of directories, e.g:

    .,D:\Program Files\AW\Maya4.0\include

    The directory where the Maya include files (.h) are stored on your computer needs to be added to this list.

  8. Add the Maya include directory to the end of the list. Be sure to use a comma (,) to separate it.

    For example, if your Maya includes files are located in the directory C:\AliasWavefront\Maya\Include then it would be added to the list as follows:

    .,D:\Program Files\AW\Maya4.0\include,C:\AliasWavefront\Maya\Include

    Notice the comma separating it from the last directory.

  9. Click on the OK button to close the Project Settings dialog box.
  10. Press F7 or select Build | Build pluginname.mll from the main menu.

    If the directory was added correctly the plugin should now compile. However it will most likely fail during the linking. An error message, like as follows will be displayed:

    ...
    Linking...
    LINK : fatal error LNK1104: cannot open file "filename.lib"
    Error executing link.exe.

    Like the include files (.h) the directory where the library files (.lib) are located must be given.

  11. Press Alt+F7 or select Project | Settings... from the main menu.
  12. Click on the Link tab.
  13. Click on the combo-box next to Category:
  14. Select Input from the drop-down list.

    The Additional library path: box will contain a list of directories. For example:

    D:\Program Files\AW\Maya4.0\lib

    The directory where the Maya libraries (.lib) are stored needs to be added to this list.

  15. Add the Maya libraries directory to the list. As before, use a comma is used to separate the directories.

    For example, if your Maya library files are located in the directory C:\AliasWavefront\Maya\lib then it would be added to the list as follows:

    D:\Program Files\AW\Maya4.0\lib,C:\AliasWavefront\Maya\lib

  16. Click on the OK button to close the Project Settings dialog box.
  17. Press F7 or select Build | Build pluginname.mll from the main menu.

    If the library directory was added correctly the plugin should now compile and link. The resulting plugin file (.mll) will be stored in the Debug subdirectory. This is the file that is loaded into Maya.

Linux

Compiling the example plugins under Linux is done using makefiles.

  1. Open a terminal/shell.

    In order to compile the plugins, the makefiles need to know where your installation of Maya is located. The environment variable $MAYA_LOCATION is typically set to the Maya directory.

  2. To see if this environment variable is set correctly, execute the following:

    echo $MAYA_LOCATION

    The Maya directory should be displayed. If it isn't you need to set the environment variable $MAYA_LOCATION to the Maya directory.

  3. Go to the directory where the companion files were unzipped to.
  4. Go to the Plugins subdirectory.

    The Plugins directory contains a makefile that will compile and link all the example plugins.

  5. Execute the following:

    make

    All the plugins will then be compiled. If you want to compile the plugins individually simply go the subdirectory containing the particular plugin and then execute make. This will make the plugin in the current directory.

 


Creating New Plugins

Windows | Linux

Windows

Minimum Requirements:

There are two ways to setup a plugin using Visual C++, the first uses the Wizard and the second is by doing it manually. The preferred method is the Wizard since it setups up the necessary project settings automatically.

Wizard

  1. Run Visual C++.
  2. Select File | New... from the main menu.
  3. Select Maya Plug-in Wizard from the list of possible projects.

    If you don't see Maya Plug-in Wizard listed then it may not have been installed. Rerun the Maya installation and ensure that the Developer's Toolkit is selected to install. The Maya setup program will automatically find the copy of Visual C++ and install the Maya wizard. Once this is done start these instructions again.

  4. In the Project name: field type in the name of your plugin, e.g. MyPlugin.
  5. In the Location: field type in the name of the directory where the plugin files will go. Alternatively use the brower button to select an existing directory.
  6. Click on the OK button.

    The Maya Plug-in Wizard will the start. The Step 1 of 3 page will be displayed.

  7. In the Please enter ... is for: select which version of Maya you'd like to create a plugin for.
  8. In the Location of developer kit select use installed copy.

    If you get the error message "Can't find an installed copy of Maya x.x" then select custom location. The custom location is the main Maya directory and NOT the devkit directory. For instance, if you copy of Maya is installed in the directory C:\AW\Maya4.0 then this is the directory to put in the custom location field.

  9. In the What is the vendor ...? field type in your name or the name of your company.
  10. Click on the Next button.

    The Step 2 of 3 page will be displayed.

  11. In the What type of plug-in ... create? section select the type of plugin you'd like to create.
  12. In the Maya type name field enter the name of the command, node, etc.
  13. Click on the Next button.

    The Step 3 of 3 page will be displayed.

  14. If you like you can change the plug-in filename in the Name of plug-in: field.
  15. The What libraries...link with? section lists those libraries that the plugin will link with. The wizard will automatically select the libraries that your plugin needs. You can select others if you think you'll need them. Don't worry if you didn't select them all now. You can edit the project later to include them.
  16. Click on the Finish button.

    The New Project Information dialog box is displayed with a list of the selected wizard options.

  17. Click on the OK button.

    The project and source code files will be created.

  18. Press F7 to build the plugin.

    The final plugin file (.mll) will be created in the Debug subdirectory.

  19. To edit the source code files click on the FileView tab at the bottom left.
  20. To show the list of files in the project expand the pluginname files item, e.g. MyPlugin files.
  21. Expand the Source Files folder.
  22. Double click on the .cpp file listed.

    You can now edit this file to change your plugin.

At any time during the wizard it is possible to skip any remaining steps by clicking on the Finish button. This will use the default values for all the remaining steps.

Linux

The sole setup for creating plugins under Linux is the creation of a makefile. Having created the makefile the plugin can be compiled by using the make command.

  1. Open a terminal/shell.
  2. In order to compile the plugins, the makefiles need to know where your installation of Maya is located. The environment variable $MAYA_LOCATION is typically set to the Maya directory.
  3. To see if this environment variable is set correctly, execute the following:

    echo $MAYA_LOCATION

    The Maya directory should be displayed. If it isn't you need to set the environment variable $MAYA_LOCATION to the Maya directory.

  4. Go to the directory where the companion files were unzipped to.
  5. Go to the Plugins/BasicLocator subdirectory.

    All the subdirectories under the Plugins directory contain a makefile that compile and link the particular plugin. It is easiest to take an existing makefile and edit it for your purposes.

  6. Copy the Makefile file to the directory where your source code is located.
  7. Open the Makefile in a text editor.
  8. Go to the line:

    OBJECTS = BasicLocator.o PluginMain.o

    This is a list of all the object files (.o) that make up the plugin. These object files are compiled from the source code files (.cpp). Simply change the line to include all your source code files (.cpp) but with the .o extension. For example, given the souce code files main.cpp and foo.cpp, change this line to:

    OBJECTS = main.o foo.o

  9. Go to the line:

    BasicLocator.so: $(OBJECTS)

    Change this to the name of the plugin. For example:

    foo.so: $(OBJECTS)

  10. Save the file. Ensure that it is named Makefile. The make command will automatically look for a file named Makefile.
  11. From the shell execute the following:

    make

    The plugin will be compiled. There will be a .o file for each of the source code files as well as the final .so file. The .so file is the final plugin and the one that is loaded in Maya using the Plug-in Manager.