0

I'm new to MEL script and working on dealing with batch render of massive files(over 10000) with MAYA, the basic prototype is like this:

import maya.mel as mel
import maya.cmds as mc
mc.file("D:/render/abc.mb",i=True)
mel.eval('RenderIntoNewWindow;')
mc.renderWindowEditor('renderView' , e=True , wi='D:/render/abc')

This is a simple script which contains three commands: import, render, saveimage.

Here is the problem. RenderIntoNewWindow seems to be an asynchronous method so that the script will proceed while rendering is in progress. Then Maya will save something like an incomplete image.

I also tried a callback method 'renderwindowssaveimagecallback'.

mel.eval('renderWindowSaveImageCallback "renderView" ("D:/render/abc") "image";')

But it didn't work either. Maya give the message "ImageFormats instance has no attribute 'oldOutf' # ".

Is there any command that i could render an image with a synchronous way? Thanks.

Puffy
  • 30
  • 6

1 Answers1

2

You probably dont want to use RenderIntoNewWindow, since this is a batch script. You can just use cmds.render() and pass in the camera you want to render. Here's a very minimal example:

cmds.setAttr("defaultRenderGlobals.imageFormat", 32)
result = cmds.render('persp', x=512, y=512)

The first line sets the render format to PNG, the second renders the image and puts the file name into the variable 'result'.

Maya makes it annoyingly clunky to control things like where the files end up, what format they are, and so on. The simplest thing to do is to set the options that work for you in the render globals window and check your script listener for the setting changes, or consult the node reference for renderGlobals For example, to specify a file name instead of just repeating the name of the maya file when you render, you could do:

 cmds.setAttr("defaultRenderGlobals.ifp",  "your_filename_here",type='string')

Doing the batch part is easy, you just loop over a list of files and do the same operation for each

filenames = ['c:/batch/a.mb', 'c:/batch/b.mb']
results = []
for eachfile in filenames:
    cmds.file(eachfile, open =True, force=True)
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32)
    # other render settings would go here
    result.append( cmds.render('persp', x=512, y=512))

print results # prints out the names of all the rendered files

A word of caution, the render setup (since it supports lots of different renderers with their own settings, from Maya to OpenGL to MentalRay to Turtle) is pretty complicated. If you expect to have to do complex configurations on the files it might be better to invest in a commercial batch render manager which has a good UI for all of the many options you'll need to work with. For simple cases (especially where the files are already set up correctly and all you want to do is render them) the above should be fine.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • many thanks for the answer. another question. cmds.render could only use MAYA default render. but what should i do if i need to user arnold? – Puffy Feb 14 '15 at 06:35
  • Try setting the currentRenderer attribute on the defaultRenderGlobals object. (set it by hand once and then see what the correct string is by checking the attribute). – theodox Feb 15 '15 at 01:48