Page 1 of 1

Hands on: Scripting

Posted: Thu Aug 09, 2012 6:09 pm
by Rogurt
Hi there

I´d like to have a already set region of an opened mxs being rendered and an image being saved with every new SL.
I thought "well just tweak that example script that is supplied by maxwell". But since I am a total scripting Dummy I won´t get anywhere.

It´s even worse: the sample "render events" script itself wont just work if I use it as is (the path for scene and image altered properly of course). The debugger (which is all Greek to me) returns: Uncaught exception at <anonymous script, id=0>:11: ReferenceError: setResX is not defined

Is there any tutorial, resource or the like to help beginners like me?

Cheers,
Rogurt

Re: Hands on: Scripting

Posted: Thu Aug 09, 2012 6:39 pm
by Mihai
I think you can just remove those two lines, it will render at the rez you have specified in the MXS anyway. Probably those two functions have changed their name...

Re: Hands on: Scripting

Posted: Thu Aug 09, 2012 7:06 pm
by Rogurt
Thanks. Without the setRes lines the "Render events" sample script starts without error. But it wont output multiple png (one for each integer SL) and it does not output any messages either as the script supposes...

Seems like the whole scripting thing is outdated. Does one only use Python these days? and how to start with this if you´re a total newbie?

Cheers
Rogurt

Re: Hands on: Scripting

Posted: Tue Aug 14, 2012 2:19 pm
by Mihai
I saw there was a missing backslash in the path naming which caused the files to be saved in the parent folder....
Here is the fixed one, and also added a way to control how many decimals the SL should be saved as in the image name. Just change the "sl.toFixed(2)" to more or less decimals as you see fit. You probably want to change the setTime and setSamplingLevel as well.

EDIT: you probably don't want to save images from the very first SL, so I added the "startAtSL" to allow you to choose from which SL it should start saving images.
Also I removed the user defined image path and file name, and instead it grabs those from the scene using Scene.imagePath. You can always change that variable if you want the output to be somewhere else.
Code: Select all
// This script shows how to register render events within a script

var mxsPath = "G:\MAXWELL\testIncr.mxs";
var startAtSL = 5;

Maxwell.print( "rendering Mxs file: " + mxsPath );
Maxwell.openMxs( mxsPath );
var imagePath = Scene.imagePath;
Scene.setSamplingLevel( 25 );
Scene.setTime( 20 );
Scene.setImagePath( imagePath );

RenderEvents["renderFinished()"].connect(renderHasFinished);
RenderEvents["samplingLevelChanged(double)"].connect(slHasChanged);
RenderEvents["renderError"].connect(errorHappened);
RenderEvents["renderWarning"].connect(warningHappened);
   
Maxwell.startRender();

//////////////////////////////////////////////////////////////////////////////////////////////////////////

function renderHasFinished()
{
  Maxwell.print( "Render finished!!" );
}

function slHasChanged(sl)
{
  Maxwell.print( "Script Info: SL Changed: " + sl);

  // Copy the current image with this SL to a different location
 
        if(startAtSL <= sl ){
	var imagePathAtSL = FileManager.getFileFolder( imagePath ) + "\" + FileManager.getFileName( imagePath ) + "_sl_" + sl.toFixed(2) + ".png";
	FileManager.copyFile( imagePath, imagePathAtSL );
        }

}

function errorHappened(err)
{
  Maxwell.print( "Script Info: Render Error: " + err );
}


function warningHappened(warning)
{
  Maxwell.print( "Script Info: Render Warning: " + warning );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////