Mar 2012
1 / 5
Mar 2012
Mar 2012

I'm trying to create a script that tells you the frame you are rendering and how many you have left.  When I click batch render I want it to set a variable (StartFrame) and everytime a frame is finshed add one to that variable.  The problem I am having is that it seems Pre Render Frame MEL and Post Render Frame MEL don't seem to trigger with a batch render.  Is there a way to have those two options work with a batch render?

  • created

    Mar '12
  • last reply

    Mar '12
  • 4

    replies

  • 5.0k

    views

  • 1

    user

I haven't used postRender scripts, but I use prerender scripts frequently.
I use python to launch my batch renders -  here is a python script that will launch a batch render and use the 'preRender' flag to source a MEL script.
The "print" statement in the Mel script will print to the log.  I would think you could add and increment a var and use a postRender script to print it after each frame, but I haven't tried it.  If it works, maybe you could replace Maya's bloated log with info that would actually be useful.
I have a more elegant solution for rendering w/Python and sourcing a Mel script, but it requires an extra external script, so I'm posting this for ease of explanation, hopefully you can get something useful out of it:

renderMe.py

'''
D:\MiscApps\Python26\python renderMe.py

'''
import os, glob, time, shutil

#############################################################
### VARS:

project = r'C:\Projects\3D'
startF = '1'
endF = '365'
imageName = '"Test_preRender\destFileName__"'
renderCam = 'audienceCam'
destPath = r'C:\Projects\Compositing'
scene2Render = r'C:\3D\scenes\aScene59.mb'
verbose = r' -v "5" '
preRndrCmd = r'"source \"D:/Software_stuff/Maya/Batch/preRenderScript\""'

print 'Start:' + time.strftime("%H:%M:%S", time.localtime())
print 'Render Components F'+ startF +' to F' + endF
os.system (' render -s ' + startF + ' -e ' + endF + ' -proj ' + project + ' -im ' + imageName + ' -r mr -cam ' + renderCam + ' -preRender ' + preRndrCmd + verbose + ' -log ./components59_rLog.log -rd ' + destPath + ' ' + scene2Render )

print 'Done:' + time.strftime("%H:%M:%S", time.localtime())
############################################################

preRenderScript.mel

// Turn off all display layers:
for ($obj in ls -type displayLayer) {
setAttr ($obj+".v") 0;
}

// Build list of layers and set visibility:
string $compLyrs[] = {"A_lyr","B_lyr","c_lyr","Universe_lyr"};

for ($lyr in $compLyrs)
{
setAttr ($lyr+".v") 1;
}

// SET RENDERLAYERS:
// Turn off all render layers:
for ($rLyr in ls -type renderLayer)
{
setAttr ($rLyr+".renderable") 0;
}

// Enable specific rLayrs for render
string $compRLyrs[] = {"ao","bty","RGBMatte","univ"};

for ($rLyr in $compRLyrs)
{
setAttr ($rLyr+".renderable") 1;
}
print "duh";

The problem is that post render and prerender live in a different process. Its like starting a second maya thats independent of your original. So even if maya does trigger those, theres really no easy way to communicate back to the main host* without major hacking**. You can on the otherhand send it to any other place as easily as back to the host.

So just setting variable to something does not do anything really, try writing to a file and youll see the data. Quite technically you do have a open command port but you dont get much flexibility in that, and ffcourse had you got 2 mayas running at once youd be dead.

  • you would need to open a host connection trough socets or something for inter proces communication.
    ** its not hard per see but its abit more advanced topic.

What i've decided to do is just make a window that starts the render when a button is pressed and have it set the variables then.
The only problem I have is when I use "render -batch;" it doesn't render in Mental Ray even if I set it to Mental Ray as the default renderer.

Also, is there a function that I can use that ticks every second until the render is finished?  I want to know the total render time, but in a GUI window I want to display the total render time and update it every second.

Also, is there a function that I can use that ticks every second until the render is finished?

Not really. You can block maya but then it wont do anything. Anyway your approaching this the wrong way use the proggressbar events.