Some MEL commands executing before others are complete

I'm trying to write a MEL script to control a hardware render for batch hardware rendering. The goal is for my script setups of some render attributes, then kicks of a GL render, then goes to the next scene (file -open) and then configures and renders that scene.

The problem I'm having is that the hardware render command is launching without all of the settings (made with setAttr's) being applied so it starts rendering an incorrect size, wrong camera, etc. In addition to that, the HW render is the immediately interuppted by the next file command.

It would seem that it's queing some of the steps to do later, but going ahead and running later commands before they're done.

Here's an example script I'm using to generate slates with a hardware render before rendering the main scene. Any ideas?

global proc bmt_renderslate (string $scn_name, string $slate_text)
{
// clear the scene to prepare for new models:

file -f -new;


//  create the text object:

string $text\_curvesj[];
string $text\_surf[];
float $text\_xyz[];

$text\_curves = `textCurves -ch 0 -f "Arial|h-13|w400|c0" -t $slate\_text`;
$text\_surf = `planarSrf -ch 1 -tol 0 -o on -po 0 $text\_curves[0]`;
delete $text\_curves[0];


//  get the bounding box of the text object, center it, and position
//  the orthographic front camera to position the text in the safe
//  area in the bottom of the frame:

$text\_xyz = `objectCenter $text\_surf[0]`;
move -r (-$text\_xyz[0]) (-$text\_xyz[1]) (-$text\_xyz[2]) $text\_surf[0];

float $bbox\_size[] = 
    eval("getAttr " + $text\_surf[0] + ".boundingBoxSize");
float $ortho\_height = $bbox\_size[1] / ((1-(1.66/1.85))/2);

setAttr frontShape.orthographicWidth ($ortho\_height * 1.66);
setAttr front.ty ($ortho\_height/2 - $bbox\_size[1]);


//  configure front camera's film gate:

setAttr "frontShape.horizontalFilmAperture" 1.66;
setAttr "frontShape.verticalFilmAperture" 1;


//  setup hardware render attributes, resolution, frame range, etc:

setAttr defaultHardwareRenderGlobals.extension 4;
setAttr "defaultHardwareRenderGlobals.startFrame" 1;
setAttr "defaultHardwareRenderGlobals.endFrame" 1;
setAttr "defaultHardwareRenderGlobals.byFrame" 1;
setAttr defaultHardwareRenderGlobals.imageFormat 3;
setAttr -type "string" defaultHardwareRenderGlobals.resolution 
    "damage 640 386 1.66";

setAttr defaultHardwareRenderGlobals.alphaSource 2;
setAttr "defaultHardwareRenderGlobals.drawStyle" 2;
setAttr "defaultHardwareRenderGlobals.texturing" 0;
setAttr "defaultHardwareRenderGlobals.lineSmoothing" 0;
setAttr "defaultHardwareRenderGlobals.fullImageResolution" 0;
setAttr "defaultHardwareRenderGlobals.geometryMask" 0;


//  setup the output image location:

eval("workspace -rt images "o:/scenes/" + $scn\_name + "/output"");
setAttr -type "string" defaultHardwareRenderGlobals.filename "slate";


//  open the hardware render display, and look through the front
//  camera:

glRenderWin;
glRenderEditor -e -lookThru frontShape hardwareRenderView;


//  render the image to disk:

// resChangedScriptJobRW glRenderWindow;
glRender -renderSequence hardwareRenderView;


//  close the render window, and clear the scene:

file -f -new;       //  clear the scene and reset

}

--Coop

--Coop

Not sure if it will work, but you might want to try putting the gl stuff at the end into an "evalDeferred" call instead of just calling it directly.