All posts related to V2
By Rogurt
#359549
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
By Rogurt
#359554
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
User avatar
By Mihai
#359673
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 );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Help with swimming pool water

I think you posted a while back that its best to u[…]

Sketchup 2026 Released

Considering how long a version for Sketchup 2025 t[…]

Greetings, One of my users with Sketchup 2025 (25[…]

Maxwell Rhino 5.2.6.8 plugin with macOS Tahoe 26

Good morning everyone, I’d like to know if t[…]