All posts related to V2
#368248
I know this may be a stretch, but I have a singular MXS file with multiple cameras (each represent a single frame from a scene in SketchUp). What I would like to do is to strip out a single MXS for each frame/camera, so I can then batch render out all frames.

Right now, the script I have to render all the cameras is this (care of JD and others). The problem is that this can only be used on a single render node, and I can't resume rendering to a higher SL (it just starts over again), so progressive rendering is off the table.

Obviously I know nothing about scripting, so any help would be appreciated.
Code: Select all
// This script loops through a set of cameras, specified by name and
// index. It must be customized to fit the characteristics of the given
// MXS file. As set up, it expects to find the MXS filled with cameras
// whose names begin with 'Scene '. This base name is stored below
// in the 'baseName' variable. It expects the scene numbers to begin
// at 1 and to end at 3, with these limits being stored below in the
// 'firstFrame' and 'lastFrame' variables. It will loop through the frame
// range looking for cameras which fit the pattern 'Scene 1', rendering
// each one as it is found.

var firstFrame = 1;
var lastFrame = 24;
var baseName = "f";

// internal vars & events

var isRendering = 0;
var currentFrame = firstFrame;
var outputFolder = FileManager.getFileFolder(Scene.mxsPath);
RenderEvents["renderFinished()"].connect(renderHasFinished);

// render loop

while (currentFrame <= lastFrame)
{
  renderCamera(currentFrame);
  while(1)
  {
    if(isRendering == 0)
    {
        break;
    }
  }
  currentFrame++;
}

// functions

function renderCamera(frameNumber)
{
  var sceneName = baseName + frameNumber;
  Mxi.setActiveCamera(sceneName);

  if (Mxi.activeCameraName != sceneName)
  {
    Maxwell.print("The MXS contains no camera named '" + sceneName + "'!");
  }
  else
  {
    Maxwell.print("rendering Scene: " + sceneName);
    Scene.setMxiPath(outputFolder +  "\" + sceneName + ".mxi");
    Scene.setImagePath(outputFolder + "\" + sceneName + ".png");   
    isRendering = 1;
    Maxwell.startRender();
  }
}

function renderHasFinished()
{
  isRendering = 0;
  Maxwell.print("Render finished!!");
}
#368354
Checking, I don't think it's possible to save out an MXS from a script running in Maxwell. Regardless, here is a python routine that will do what you want:
Code: Select all
########################################################
# extract_cameras_to_mxs_files.py
#
# Opens a specified MXS file and cycles through its
# cameras, writing new MXS files for each. Depending
# on the provided "incremental" variable, these MXS
# files will either be named based on the name of the
# input MXS, or they will be named for their camera.
#
# User variables:
#
#   mxs_dir:     directory containing the source MXS
#   mxs_name:    source MXS name, without extension
#   incremental: if True, output MXS files are named
#                incrementally (i.e. name_0001.mxs)
#
########################################################

mxs_dir     = r'c:\users\jeremy\desktop\anim test';
mxs_name    = r'test';
incremental = True; # note: True/False, case sensitive

########################################################
# internal stuff
########################################################

from os import *
from pymaxwell import *

infile = path.join(mxs_dir, mxs_name + '.mxs');

channels = [
  "render",
  "alpha",
  "z",
  "shadow",
  "material",
  "object",
  "motion",
  "roughness",
  "fresnel",
  "normals",
  "position"
];

def extract_cameras_to_mxs_files():
  ret = 0;
  if not path.exists(infile):
    ret = 1;
    print(infile + " does not exist.");
  else:
    mw = Cmaxwell(mwcallback);
    if not mw.readMXS(infile):
      ret = 1;
      print("Failed to read " + infile);
    else:
      f = 1;
      it = CmaxwellCameraIterator();
      cam = it.first(mw);
      while not cam.isNull():
        cam.setActive();
        if incremental:
          fbase = "%s_%.4i" % (mxs_name, f);       
        else:
          fbase = "%s" % cam.getName();
        for c in channels:
          imginfo = mw.getPath(c, 8);
          if str(imginfo[0] or '') != '':
            imgbpc = imginfo[1];
            split = path.splitext(imginfo[0]);
            if len(split) > 1:
              imgext = split[1];
              if c == "render":
                imgname = "%s%s" % (fbase, imgext);
              else:
                imgname = "%s_%s%s" % (fbase, c, imgext);
              imgpath = path.join(mxs_dir, imgname);
              mw.setPath(c, imgpath, imgbpc);
        mxiname = "%s.mxi" % fbase;
        mxipath = path.join(mxs_dir, mxiname);
        mw.setRenderParameter("MXI FULLNAME", mxipath);
        outname = "%s.mxs" % fbase;
        outpath = path.join(mxs_dir, outname);
        if not mw.writeMXS(outpath):
          print("Failed to write " + outpath);
        else:
          print("Wrote " + outpath);
        f += 1;
        cam = it.next();
    mw.freeScene(); 
  return ret;

extract_cameras_to_mxs_files();
As described in the notes, you can decide whether to write the output files incrementally, or according to camera name. It doesn't actually remove any cameras, it just sets each one active before writing out its MXS file. To run it, use pymaxwell.exe in your Maxwell 2 folder. Note that python uses indentation to determine how code works.

[edit: it is not clear what should be done with paths for channel and mxi outputs; with no modification, they might go anywhere, so along with the image output, they are rewritten to render into the same directory as the MXS.]
#368454
Code: Select all
>> Traceback (most recent call last):
  File "<string>", line 90, in <module>
  File "<string>", line 69, in extract_cameras_to_mxs_files
  File "C:\Program Files\Next Limit\Maxwell 2\lib\ntpath.py", line 190, in splitext
    return genericpath._splitext(p, sep, altsep, extsep)
  File "C:\Program Files\Next Limit\Maxwell 2\lib\genericpath.py", line 94, in _splitext
    sepIndex = max(sepIndex, altsepIndex)
RuntimeError: setPath: error
Keep getting the same error message, no matter what I tweak/try.

Hi there, after a texture tag has been assigned to[…]

Rhino6 Plugin / Rhino Crash

Having fun on my own thread here :) It appears tha[…]

The script will be useful and i think it is easy t[…]