Results 1 to 2 of 2

Thread: Python scripts for mental ray advanced production

  1. #1
    Join Date
    Dec 2004
    Marina Del Rey, California

    Default Python scripts for mental ray advanced production

    Python scripts for using mental ray in Maya

    We are sharing Python scripts for using mental ray standalone from Maya, as well as taking advantage of some newer features of 3.9 like userdata

    Use these work-in-progress scripts at your own risk. They take advantage of new things we are developing, but we want those of you who can to share your suggestions. As we start this project, we will keep our own repository, so that we can manage the process.

    We welcome suggestions from both artists and Maya Python programmers. We know the current state is not perfect in its modularity and naming, but want to use somewhat of an Agile process for fetaure release and refactoring.

    We should start two separate threads, one for usage feedback, and another for Python developers who want to share suggested implementation changes. This one will be locked and sticky, as it will contain the latest download at any given time.

    Note that we are planning on separating the in-Maya UI from the standalone export and render, as we have had a lot of requests to be able to use unified sampling and other useful modern rendering techniques from within Maya. Ie, we will make it easier to use the easier-to-use features.
    Last edited by bart; May 16th, 2012 at 21:55.
    Barton Gawboy

  2. #2
    Join Date
    Dec 2004
    Marina Del Rey, California


    Basic installation of scripts which we will rewrite as we go ...

    Run mental ray standalone from within Maya

    A UI to attach to the Maya shelf for using mental ray standalone

    Download scripts from above post

    Use these Python scripts to:

    render with iray from Maya
    render with the latest standalone release
    render mr standalone with a single button click
    render several iterations of a scene to different images
    keep track of log files for each


    After unpacking the zip file, the mr directory is a Python package that contains several subdirectories of scripts. Place the whole mr package in a convenient location for later reference. For example, for training class on Windows machines, we will put them in C:/MRT/maya/scripts . They could also be placed in the location Maya looks for scripts by default. If you type in mayapy to get a Maya Python listener, you can see the typical paths searched by doing:

    >>> import sys
    >>> sys.path

    The sys.path variable contains the paths where Python will look for packages and modules.


    The simplest installation is no installation; ie, use the Python that comes with Maya. That executable, as mentioned earlier, is mayapy and is in the bin directory of the Maya installation. The next most simple installation would use a version of Python from We have tested 2.6, 2.7, and 3.1 for compatibility. Using at least version 2.6.4 or greater matches Maya 2010 or 2011. We have now put in a check and a warning if you use an earlier version. If using Linux or Mac OS X with pre-installed Python, check your python version with python -V

    For the mental ray standalone UI, you will need:


    Creating Maya shelf button

    A user can make a button on the shelf, which runs a python script; we tend to put it in the Custom category. To do this, open the Shelf Editor ...

    and in the Shelf Editor, create a new item. See red highlight box below indicating new item icon. Name it whatever you like, eg, a button named "ray3.9 Maya UI"

    Add a short script to your new button under the Command tab of the Shelf Editor for that newly created button. Here is an example of the script that runs the Maya Python UI. Note that the Python radio button is selected rather than the MEL radio button. Check this if you are seeing unexpected errors.


    Below is the general comment we supply in the scripts for setting up the commeands. Again, remember to choose Python rather than MEL in the command tab. Change the scripts_path to indicate where you put these scripts on your machine. Those top three lines (the scripts path addition to PATH) are not needed if you use the PYTHONPATH env variable for Maya, or put it in a standard location that Maya looks for scripts, as mentioned in the Installation section above.

    ################ Typical script editor Python ################
    # import sys
    # scripts_path = "C:/path/to/your/scripts"
    # sys.path.append(scripts_path)
    # import mr.standalone.ui as mrui
    # mrui.standalone_window.create()
    ##### or replace 'mrui.standalone_window.create()' with
    ##### 'mrui.standalone_window.render()' for a 1-click render.
    ################################################## ############

    Note in the comment in the bottom of the upper box, that we use both the single click and double click command. In one we bring up the window UI, and the other we use the last settings to immediately render.


    That should be all you need to get the UI running. Once you load the UI for the first time, you will want to set some of the default values.


    Under the Path/Info tab you have four options. Make sure that ray_path, python_path, text_editor, and image_viewer are all set correctly for your computer. The python_path can be either a fully specified path, or a command. For example, one could set it to mayapy or to a current version of python on your computer. Your global settings will be saved in an mi directory under the directory specified by the HOME environment variable. We also present the locations for local and global settings files, along with some buttons to help debug with version information.



    In the Export tab of the UI shown below, note that the render directory has nothing in it. That means it will use the current Maya project by default. You can override that by specifying a path here. To go back to the current Maya project, erase the path from this text box.

    Clean Export removes the Maya Glow framebuffer, and uses exact hierarchy names. We decided not to put legacy shader switching in that, since 3.9 compiled AD shaders now seem to work much better. This does not affect the actual scene export settings, just the mi export for this button, as we restore state.



    In the Settings tab of the UI, we have three subtabs for Common , iray, Unified Sampling and Indirect Lighting settings. For example, a checkbox for iray adds "iray" on in the scene's string options. When first opening the UI, the simplest options are presented on top. Additional options are presented in the expandable sections below them.



    We offer gpu, cpu or mixed mode selection. And then limit our simplest basic settings to time and max samples. Each can be set to unlimited, for which the user must typically hit the stop button from the imf_disp display of the rendering image.


    Unified Sampling

    We present unified for three modes of mental ray rendering, regular raytracing, progressive raytracing and the rasterizer. Typically, one might use progressive to set up a render using regular.

    For the simplest basic usage, we display only the samples quality.


    Indirect Lighting

    work-in-progress reorganization of indirect lighting

    currently using this actually modifies your scene's indirect settings which are not string options, such as most of the FG settings
    Barton Gawboy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts