Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

MEL script rendering wrong camera

MEL script rendering wrong camera

J-Fry
Enthusiast Enthusiast
67 Views
1 Reply
Message 1 of 2

MEL script rendering wrong camera

J-Fry
Enthusiast
Enthusiast

Hi,

I have a bunch of scenes to render but they are all pretty short (40-200 frames). I am trying to set up a post render MEL script that opens the next scene file and kicks off that render. So I don't have to be there to start the next scene render when one finishes.

 

I am able to get it to open up the next scene and start the render, but I cannot get it to use the correct camera (renderCam). It just renders with the persp camera every time. I tried to force it to use "renderCam" in the MEL script, but it still renders using the persp camera.

 

Can somebody explain how to get it to render the camera in the render settings instead of the persp camera?

 

Here is the current (broken) script:

global proc forceRenderSequenceCamera2(string $targetCamShape) {
    string $nextScene = "D:/maya/projects/myProject/scenes/myScene2.ma";
    // Open the next scene
    file -f -open $nextScene;

    pause -sec 2;  // Give Maya time to settle

// Wait until the camera exists and is renderable
while (!`objExists "renderCamShape"` || !`getAttr "renderCamShape.renderable"`) {
    pause -sec 1;
}
    
    // Get all cameras in the scene
    string $allCameras[] = `ls -type "camera"`;

    // Disable renderable on all cameras
    for ($cam in $allCameras) {
        if (`objExists $cam`) {
            setAttr ($cam + ".renderable") 0;
        }
    }

    // Enable renderable on the target camera
    setAttr ($targetCamShape + ".renderable") 1;

    // Force the active panel to look through it
    string $panel = `getPanel -withFocus`;
    lookThru $targetCamShape;

    // Run RenderSequence
    RenderSequence;
}

 

0 Likes
68 Views
1 Reply
Reply (1)
Message 2 of 2

malcolm_341
Collaborator
Collaborator

@J-Fry 
This was really confusing, I believe the issue is because Arnold ignoes what camera you set in render globals and has it's own override for the Arnold render sequence. I looked at this for a couple hours and found a hack that works, maybe someone has a cleaner way to do this, but give it a try it works for me and you can remove all the parts of your script that modify properties on cameras. The trick here is to render one frame in the Arnold render view to force the camera to renderCamShape.

 

//Reset render globals to default
python "import maya.app.renderSetup.views.renderSetupPreferences as prefs ; prefs.setDefaultPreset()";

//File type
setAttr "defaultArnoldDriver.aiTranslator" -type "string" "png";
//File output folder and file name
setAttr "defaultRenderGlobals.imageFilePrefix" -type "string" "C:\\Users\\malco\\Desktop\\render_test\\output_folder\\yourFileName";

//Turn on multi frame render
setAttr "defaultRenderGlobals.animation" 1;
//Turn on padding 4
setAttr "defaultRenderGlobals.extensionPadding" 4;
//Turn on name.#.ext
setAttr "defaultRenderGlobals.putFrameBeforeExt" 1;
setAttr "defaultRenderGlobals.periodInExt" 2;


//Resolution
setAttr "defaultResolution.aspectLock" 1;
setAttr "defaultResolution.width" 200;
setAttr "defaultResolution.height" 200;
//You need to set the device aspect ratio to match whatever resolution you put in your script
//To find this number under image size in the render globals UI type in your width height and see what the UI automatically sets your device aspect ratio to
//1920x1080 1.778 device aspect ratio, in this example script it's square so you set it to 1
setAttr "defaultResolution.deviceAspectRatio" 1;
setAttr "defaultResolution.pixelAspect" 1;


//Turn on animation range
setAttr "defaultRenderGlobals.animationRange" 0;
//Set the start frame
setAttr "defaultRenderGlobals.startFrame" 0;
//Set the end frame
setAttr "defaultRenderGlobals.endFrame" 5;

//Render one frame to set the camera you want
arnoldRender -camera "renderCamShape";

//Render the whole sequence
renderSequence;

 

 

0 Likes