All posts related to V2
By whitecorals
#341571
Hi,

I am trying to write a script for my batch renders based on the example script “progressive_animation” available in the scripts folder in Maxwell.

I found the script “progressive_animation” usefull to progressively render different stills, basically I set my target SL for the script and let it render whatever is in the “input” folder defined in the script.

Occasionally I am adding some new files to the input folder and rerun the script, everything is fine my newly added MXS files will start render until they reach the same SL number as the other files in the “input” folder, before continuing to progressively render the rest of the files to a higher SL.
Now the problem! While basically everything works fine the script has no way to tell what the current SL number of the loaded files is, after I rerun the script, until it calls the rendering function. This is a problem because it makes loops in the script very slow, with only 10 files the loops in the scrip are taking too much time!

After checking the Maxwell manual I could only find how to do:

Var myVar = Scene.samplingLevel();

Witch gives me the maximum SL of a file a value that seems to stay constant no matter what SL the file reached already.
This function can be called just after loading the file and is very fast.

But what I need is something like this:

Var myVar = Scene.currentSamplingLevel();

Is there a function to get the current SL number of a file?

Thanks in advance
By Aji Enrico
#341577
So if I understand you correctly, you want a solution to get the SL info of a current mxi file without calling Maxwell.startRender() function because that function is too slow while going through several of mxs files (loading, voxelizing etc)?
User avatar
By tom
#341583
No, it's not there, yet. I meant it should not be requested from the scene but mxi. Because, the scene itself cannot have a current SL. ;)
By whitecorals
#341595
So I am trying to read the SL number from an MXI file but no success I must be getting it wrong!

To make things more clear, here is my script:


var inputFolder = "D:\projects\Maxwell\Scripted renders\input";
var outputFolder = "D:\projects\Maxwell\Scripted renders\output";

var mxsCount = FileManager.getNumberOfFilesInFolder( inputFolder, "*.mxs" );
var mxsList = FileManager.getFilesInFolder( inputFolder, "*.mxs" );
var mxiList = FileManager.getFilesInFolder( outputFolder, "*.mxi" );

RenderEvents["renderFinished()"].connect(renderHasFinished);

var initialSL = 4;
var finalSL = 21;
var slStep = 1;
var SL = initialSL;

var i = 0;
var isRendering = 0;

while( SL <= finalSL )
{
for( i = 0; i < mxsCount; i++ )
{
renderScene();
while( 1 )
{
if( isRendering == 0 )
{
break;
}
}
}

SL += slStep;
}

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

function renderScene()
{
var mxsFile = mxsList;

var imagePath = outputFolder + "\" + FileManager.getFileName( mxsFile ) + ".png";
var mxiPath = outputFolder + "\" + FileManager.getFileName( mxsFile ) + ".mxi";

Maxwell.print( "rendering Mxs file: " + mxsFile );

///loading both MXI & MXS file
Maxwell.openMxi( mxiPath);
Maxwell.openMxs( mxsFile );

Scene.setImagePath( imagePath );
Scene.setMxiPath( mxiPath );

//Getting the SL number from the MXI the compiler stops at this line!
var currentSL = Mxi.samplingLevel;

Maxwell.print( "File current SL: " + currentSL );

if (currentSL < SL) {
Scene.setSamplingLevel( SL );
Scene.setResumeRenderEnabled( true );

isRendering = 1;
Maxwell.startRender();
}else{
Maxwell.print( "Current SL is higher then the target SL!!" );
}
}

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

function renderHasFinished()
{
isRendering = 0;

Maxwell.print( "Render finished!!" );
}
By Aji Enrico
#341602
Try this solution until until Mxi.samplingLevel get implemented (if it gets...)
This is not an elegant solution but it works :)

As always, backup your stuff first. Using this script along with SLReader is not guaranteed to work
Code: Select all
Maxwell.clearConsole();

// point to the MXI file you want to get the SL info of
var filePath = "C:\mxm\m\Output\cornell_v2.mxi";

// point to the SLReader file
var SLReaderPath = "c:\SLReader.exe";


var folderPath = FileManager.getFileFolder(filePath);
Maxwell.print(folderPath);
var cmdPath = "c:\windows\system32\cmd.exe";
var cmdArg = [ "/c",  "C:/Program Files/Next Limit/Maxwell 2/mximerge.exe", "-mxiinfo:" + filePath, ">>", folderPath+ "\temp.txt" ];

Maxwell.launchProcessAndWait(cmdPath, cmdArg);


var SLReaderArg = ["/SLOutput=C:\mxm\m\Output\"];
Maxwell.launchProcessAndWait(SLReaderPath, SLReaderArg);

var Files = FileManager.getFilesInFolder("c:\mxm\m\output\SLInfo\", "*.txt");

currentSamplingLevel = FileManager.getFileName(Files);
Maxwell.print(currentSamplingLevel);
variable currentSamplingLevel gives you the SL of a MXI file in Maxwell script.
You do not have the required permissions to view the files attached to this post.
By whitecorals
#341648
Hi,

So here the final version of the working script, after implementing Aji Enrico's solution.

Note that for some reason I had to use DOS 8.3 format for folder names with spaces to make it work!
Code: Select all
// This script is a modified version of the "Progressive Animation" script
//  This script gets all the mxs's located in the folder "input"
//  Renders them until a desired Initial SL, to get a first version of the whole sequence, allowing the user to start the postproduction process 
//  Then continues refining the sequence until the Final SL, advancing in certain steps (slStep), offering continuous refinement 


// Edit the following lines with your own project Input and Output folders// folders name with spaces needs to be represented in 8.3 DOS format!
var inputFolder = "D:\projects\Maxwell\SCRIPT~1\input";
var outputFolder = "D:\projects\Maxwell\SCRIPT~1\output";

// point to the SLReader file
var SLReaderPath = "D:\projects\Maxwell\tools\SLReader.exe";

//Maxwell root folder// folders names with spaces needs to be represented in 8.3 DOS format!
var maxwellPath = "c:\Progra~1\NextLi~1\Maxwel~1";

var cmdPath = "c:\windows\system32\cmd.exe";

// The following SL values can be customized to fit your needs
var initialSL = 10;
var finalSL = 21;
var slStep = 1;
/////////////////////////////////////////////////////////////////////////

var mxiPath = "";
var mxsCount =  FileManager.getNumberOfFilesInFolder( inputFolder, "*.mxs" );
var mxsList = FileManager.getFilesInFolder( inputFolder, "*.mxs" );
var mxiList = FileManager.getFilesInFolder( outputFolder, "*.mxi" );

RenderEvents["renderFinished()"].connect(renderHasFinished);

var SL = initialSL;
var currentSL =0;
var i = 0;
var isRendering = 0;

while( SL <= finalSL )
{
  for( i = 0; i < mxsCount; i++ )
  {
    renderScene();
    Report();
    while( 1 )
    {
      if( isRendering == 0 )
      {
          break;
      }
    }
  }
  if(SL == finalSL){Maxwell.print("Done!");}
  SL += slStep;
}

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

function renderScene()
{
  var mxsFile = mxsList[i];
  var imagePath = outputFolder + "\" + FileManager.getFileName( mxsFile )+ ".png";
  mxiPath = outputFolder + "\" + FileManager.getFileName( mxsFile )+ ".mxi";

 currentSL = getCurrentSL();
 
  if ( currentSL < SL) {
      Maxwell.print( "rendering Mxs file: " + mxsFile );
      Maxwell.openMxs( mxsFile );
      Scene.setImagePath( imagePath );
      Scene.setMxiPath( mxiPath );
      Scene.setSamplingLevel( SL );
      Scene.setResumeRenderEnabled( true );
      isRendering = 1;
     Maxwell.startRender();
   }else{
     Maxwell.print( "Current SL is higher then target SL! will skip to next file" );
   }
}

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

function renderHasFinished()
{
  isRendering = 0;

  Maxwell.print( "Render finished!!" );
}

//////////////////////////////////////////////////////////////////
function getCurrentSL(currentSamplingLevel)
{
  var cmdArg = [ "/c", maxwellPath+"\mximerge.exe -mxiinfo:"+mxiPath+">"+outputFolder+"\temp.txt" ];

  Maxwell.launchProcessAndWait(cmdPath, cmdArg);

  var SLReaderArg = ["/SLOutput="+outputFolder+"\"];
  Maxwell.launchProcessAndWait(SLReaderPath, SLReaderArg);

  var Files = FileManager.getFilesInFolder(outputFolder+"\SLInfo\", "*.txt");

  currentSamplingLevel = FileManager.getFileName(Files);

 return currentSamplingLevel;
}
//////////////////////////////////////////////////////////////////
function Report()
{
  Maxwell.print("Mxi path:"+ mxiPath);
  Maxwell.print("SL step:"+ SL);
  Maxwell.print("current SL:"+ currentSL);
}
By Aji Enrico
#341651
Nice, haven't tried your script yet but it looks good and clean.
Is the script running noticeably faster now? Let me know if find any flaws.

Just as a note to Nextlimit team, I would also love to see this "mxi.currentSampleLevel" implemented if possible, take this as a humble feature request :)

cheers
By whitecorals
#341664
Aji Enrico wrote:Nice, haven't tried your script yet but it looks good and clean.
Is the script running noticeably faster now? Let me know if find any flaws.

Just as a note to Nextlimit team, I would also love to see this "mxi.currentSampleLevel" implemented if possible, take this as a humble feature request :)

cheers
So I got the script to run around 3 times faster with this solution.
Still kind of slow but much better.

As a test I let the script loop 20 times with an MXS of 130MB I can't tell much about the complexity of this one but it does use displacement.

with the older script it took 4:55 with new solution around 1:36

Yes it would be great if we can still get an "mxi.currentSampleLevel" :wink:
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[…]