Python "it" Scripting
Adding to the Commands Menu

return to main index


Menu items can be added to the Commands menu of the 'it' window relatively easily. Pixar's document,
    "it" Custom Commands
provides a clear explanation of how it is done. This tutorial presents an example of a python script that can be directly executed from the Commands menu - figure 1. It does not use any dialogs, windows or any other UI elements. For examples of custom commands that use a UI refer to these links,
    save all
    email image

Figure 1

To function as a menu item the script must,
    - implement a sub-class of Pixar's it.It3Command base class,
    - assign a value (the menu item label) to the m_menuPath instance variable,
    - implement a method called Invoke(), and finally,
    - call itself via it.commands.append(Thumbnail).

The python code is shown next.

import it, os
from it.It3Command import It3Command
class Thumbnail(It3Command):
    def __init__(self):
        self.m_menuPath = 'Commands/Save Thumbnail'
    def Invoke(self):
    def save_thumbnail(self, gamma=1.0,quality=100):   
        element = it.GetCurrentElement()
        image_name = element.GetLabel() + '.jpg'
        cwdpath = os.getcwd()
        path = os.path.join(cwdpath, image_name)
        self.saveImage(element, path, 2.2, 100)'The thumbnail has been saved as "%s"' % os.path.abspath(path))
    def saveImage(self, element,path,gamma,quality):
        image = element.GetImage()
        image = image.Gamma(gamma);
        # dimensions, True preserve aspect ratio, True crop to preserve aspect ratio
        image = image.Reformat([0,150,0,150], True, True)
        image.SetMetaDataItem('JPEG_QUALITY', quality)
        image.Save(path, ice.constants.FMT_JPEG)    

Installing & Loading the Script

Save the python script in your custom "it" scripts directory. For example, the "RfM: Customizing" tutorial recommends using this directory,
The users custom "it.ini" script must install the python script when Maya loads the RenderMan_for_Maya plugin. The "RfM: Customizing" tutorial recommends using the following path,

The "it.ini" script should contain a command of the following form (Windows).

    LoadExtension python "C:/Users/YOUR_NAME/Documents/maya/projects/RfM_it/"

If the user has set an environment variable called MAYA_USER_DIR that "points" to the location of their maya directory the following command can be used.

    LoadExtension python "[GetEnv MAYA_USER_DIR]/projects/RfM_it/"

© 2002- Malcolm Kesson. All rights reserved.