Page 1 of 1
Anyway to render all cameras in MXS?
Posted: Sat Aug 19, 2017 8:01 pm
by cosoli
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!
Re: Anyway to render all cameras in MXS?
Posted: Sun Aug 20, 2017 6:00 am
by seghier
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
Re: Anyway to render all cameras in MXS?
Posted: Sun Aug 20, 2017 12:46 pm
by seghier
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;
}
}
}
Re: Anyway to render all cameras in MXS?
Posted: Sun Aug 20, 2017 5:33 pm
by cosoli
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!

Re: Anyway to render all cameras in MXS?
Posted: Tue Aug 22, 2017 6:27 pm
by seghier
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 allfrom 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);
Re: Anyway to render all cameras in MXS?
Posted: Wed Aug 30, 2017 7:00 pm
by seghier
Hi
i 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
https://www.dropbox.com/s/bzx42qj2x2f2z ... s.rar?dl=0
Re: Anyway to render all cameras in MXS?
Posted: Wed Aug 30, 2017 7:33 pm
by Mihai
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
Re: Anyway to render all cameras in MXS?
Posted: Wed Aug 30, 2017 7:41 pm
by seghier
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
Re: Anyway to render all cameras in MXS?
Posted: Thu Aug 31, 2017 12:15 am
by Mihai
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

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.
Re: Anyway to render all cameras in MXS?
Posted: Thu Aug 31, 2017 12:34 am
by seghier
maybe one exe to run exist script without need to create hundreds of buttons in one application
and i can't waiting someone who know python to create what i need ; learning yes, and i will post million of threads to learn better
Re: Anyway to render all cameras in MXS?
Posted: Fri Sep 01, 2017 7:15 pm
by cosoli
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)
Re: Anyway to render all cameras in MXS?
Posted: Fri Sep 01, 2017 7:37 pm
by seghier
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

Re: Anyway to render all cameras in MXS?
Posted: Sat Sep 02, 2017 12:26 am
by seghier
Re: Anyway to render all cameras in MXS?
Posted: Wed Jul 18, 2018 4:02 am
by Raphael Tobar
This is so useful. Thank you for sharing Seghier!