Everything related to Studio.
By cosoli
#395125
How can I use script to render all cameras in the MXS ?
This is the script I used:

var inputFolder = "C:\input";
var outputFolder = "C:\output";

var engineVersion = Maxwell.getEngineVersion();

var mxsCount = FileManager.getNumberOfFilesInBranch( inputFolder, "*.mxs" );
var mxsList = FileManager.getFilesInBranch( inputFolder, "*.mxs" );

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


var i = 0;
var isRendering = 0;

// to set the number of camera in the scene
var c = 5;

// to set each camera name
var k = ["From Yard","Living Room","Approach","Section Perspective","Kitchen"];

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

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


function renderScene()
{
var mxsFile = mxsList[0];
var imagePath = outputFolder + "\" + "%scenename%" + "_" + "%camera%" + ".png";
var mxiPath = outputFolder + "\" + "%scenename%" + "_" + "%camera%" + ".mxi";

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

Maxwell.openMxs( mxsFile );
Mxi.setActiveCamera(k [ i ]);
Scene.setImagePath( imagePath );
Scene.setMxiPath( mxiPath );
Scene.setSamplingLevel( 4 );
Scene.setTime( 1 );

Scene.setAlphaChannelEnabled(1);
Scene.setMaterialIDChannelEnabled(1);

isRendering = 1;
Maxwell.startRender();
}

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

function renderHasFinished()
{
isRendering = 0;

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

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



The key issue for me is that using this script I always need to modify the number of camera or camera's name manually

Can anyone teach me how to improve this script? (The easy way to render all cameras in one MXS)

TKS!
User avatar
By seghier
#395127
hello
in this line don't use names ; use numbers
// to set each camera name
var k = ["From Yard","Living Room","Approach","Section Perspective","Kitchen"];

// to set each camera name
var i = ["1","2","3","4","5"];


and in this line : Mxi.setActiveCamera(k [ i ]); change it to : Mxi.setActiveCamera( i );

if it is possible to count the cameras number that's better
By cosoli
#395130
seghier wrote:
Sun Aug 20, 2017 12:46 pm
after test you don't need the line of cameras name:

// to set the number of camera in the scene
var c = 3;
for( i = 0; i < c; i++ )
{
renderScene();
while( 1 )
{
if( isRendering == 0 )
{
break;
}
}
}
It works!

Thanks a lot! :D
User avatar
By seghier
#395171
you are welcome
i create this python script with help of Luis ; you can use it to render all cameras in the scene
Code: Select all
from pymaxwell import *

def render_all_cameras(inFolder,inPath,outFolder):

  scene = Cmaxwell(mwcallback);
  scene.readMXS(inPath)
  cameraNames = scene.getCameraNames()
  for name in cameraNames:
    camera = scene.getCamera(name)
    camera.setActive()
    outPath = inPath
    ok = scene.writeMXS(outPath);


    parameters = []
    parameters.append('-mxs:'+inPath);
    parameters.append('-nowait');
    parameters.append('-nogui');
    parameters.append('-res:300x200');
    parameters.append('-s:6');
    parameters.append('-o:'+outFolder+'/m_%camera%.png');
    parameters.append('-mxi:'+outFolder+'/m_%camera%.mxi');
    parameters.append('-res:300x200');
    parameters.append('-time:10');
    runMaxwell(parameters)


if __name__ == "__main__":
   inFolder = 'input_folder'
   inPath = 'mxs_file'
   outFolder = 'output_folder'
   render_all_cameras(inFolder,inPath,outFolder);
User avatar
By Mihai
#395263
This is a great initiative, there are a few more tools I would find very useful to automate with pymaxwell.

Maybe we can start a thread about what a "Maxwell toolbox" should hold.

- replace a certain material (could use wildcards) with another (loaded from a MXM file)
- replace MXS references with another (could use wildcards)
- replace a texture in a material with another, keeping the texture picker settings
User avatar
By seghier
#395264
I think there are scripts in maxwell folder do that : change materials , replace mxs reference .... And more
Adding button and prepare the exe file sometimes easy , sometimes difficult because it need experience with python and pymaxwell
I will try to convert more scripts like
Change mxs reference / change material mxm
User avatar
By Mihai
#395269
There needs to be more to it than that I think cause ideally all these functionalities should be grouped under one UI, not each one as separate exes.
Also there needs to be some discussion on how to implement them. So it will get a bit complex, beyond yours or my next to no knowledge of Python.

Maybe Brany can help from time to time, or someone else with experience with Python. We need someone who knows Python. You can't post 100 threads now to ask beginner python questions, it will flood the forum with never ending python stuff. So please keep that in mind before moving on. If you're eager to learn more about programming in Python and creating this toolbox, please do :mrgreen: Just saying it will be quite a struggle and maaaany threads started to ask for basic programming help for a project which is a bit beyond basic level.
By cosoli
#395292
seghier wrote:
Wed Aug 30, 2017 7:00 pm
convert the script to executable file ( with help of Brany in my thread in SDK forum section ) to render all views in mxs scene
you must use the macro %camera% when save files
It's amazing!!!!!

How do you learn this?

I'm also interested in script

But, when I tried this script, My pc seems can run but can't save the file? (My file name use m_%camera%.png)
User avatar
By seghier
#395293

It's amazing!!!!!

How do you learn this?

I'm also interested in script

But, when I tried this script, My pc seems can run but can't save the file? (My file name use m_%camera%.png)
thanks ; i work to improve it (now the %camera% macro added automatically) and i add some options but it not finished yet
Image
Will there be a Maxwell Render 6 ?

Let's be realistic. What's left of NL is only milk[…]