Everything related to Maxwell Render and general stuff that doesn't fit in other categories.
User avatar
By seghier
#395179
a little change : i save the same scene and use it
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);
By luis.hijarrubia
#395192
seghier wrote:
Wed Aug 23, 2017 6:39 pm
in studio or with command line
when i add this macro (%camera%) to create mxs output the name don't change like image and mxi
is this a bug ?
Not sure macros work with mxs files. Will try to find out.
By luis.hijarrubia
#395193
seghier wrote:
Thu Aug 24, 2017 6:54 am
How to add and assign materials with python
i tried with : addmaterial ; set material without success
and all time if some lines are not aligned i got errors
The alignment is python mandatory. A thing that I hate, but python is like that.

For materials I do it like this:
Code: Select all
newMat = scene.createMaterial("tmpMaterial")
mainObj = scene.getObject("My Object")
mainObj.setMaterial(newMat)

if not newMat.read("c:/path/to/material.mxm"):
   print("ERROR: cannot open c:/path/to/material.mxm")
So, I first create a new material, assign it to the object, and then read a mxm on that material.
Last edited by luis.hijarrubia on Thu Aug 24, 2017 2:20 pm, edited 1 time in total.
User avatar
By seghier
#395195
thanks Luis ; sometimes even the code is correct the i thinked it is incorret because of alignment
---
the code after many tries it work fine
newMat = scene.createMaterial('default')
mainObj = scene.getObject(planeName)
mainObj.setMaterial(newMat)
if not newMat.read(newM):
print ('ERROR: cannot open newM')

-----
newM = 'C:/Program Files/Next Limit/Maxwell Render 4/materials database/mxm files/default.mxm'
User avatar
By seghier
#395196
thanks Luis ; i create this code to add infinite plane to maxwell scenes with default material ; it's not big thing but can help and maybe someone make the script better
Code: Select all
################################################################
# add infinite plane to mxs file.
################################################################

from pymaxwell import *
import os

  # plane size and name & input mxs name $ input, output scene folder

val = 500
planeName = 'Infinite Plane'
scene_name = 'new'              #name of scene in input folder
inputFolder = 'c:/'+'intest'    #change drive letter and folder name
outputFolder = 'c:/'+'outtest'  #change drive letter and folder name


################################################################

def createInfinitePlane(outFolder,outMxs):

	scene = Cmaxwell(mwcallback);
	name = planeName;
	nVertices = 4;
	nNormals = 4;
	nTriangles = 2;
	nPositionsPerVertex = 1;
	object = scene.createMesh(name,nVertices,nNormals,nTriangles,nPositionsPerVertex);


	# Vertices

	v1 = Cvector(-val,0,-val);
	v2 = Cvector(-val,0,val);
	v3 = Cvector(val,0,-val);
	v4 = Cvector(val,0,val);

	ok  = object.setVertex(0,0,v1);
	ok |= object.setVertex(1,0,v2);
	ok |= object.setVertex(2,0,v3);
	ok |= object.setVertex(3,0,v4);

	# Normals

	n1 = Cvector(0,10,0);
	n2 = Cvector(0,10,0);
	n3 = Cvector(0,10,0);
	n4 = Cvector(0,10,0);

	ok  = object.setNormal(0,0,n1);
	ok |= object.setNormal(1,0,n2);
	ok |= object.setNormal(2,0,n3);
	ok |= object.setNormal(3,0,n4);

	# Triangles

	# Triangle 0 using vertices and normals 0, 1 and 2
	ok  = object.setTriangle(0,0,1,2,0,1,2);

	# Triangle 1 using vertices and normals 2, 1 and 3
	ok |= object.setTriangle(1,2,1,3,2,1,3);

	# Save scene
	outPath = outFolder+'/'+outMxs
	ok = scene.writeMXS(outPath);

	#plane = Cmaxwell(mwcallback)
	#ok2 = plane.readMXS(inMxs2)


if __name__ == "__main__":
	outFolder = 'C:/tmp'
	outMxs = 'tmp_infinite_plane.mxs'


	createInfinitePlane(outFolder,outMxs);

################################################################

def add_inf_plane_to_scene(inMxs1,inMxs2,outFolder,outMxs,newM):

	# Read MXSs
	scene = Cmaxwell(mwcallback)
	ok1 = scene.readMXS(inMxs1)

	plane = Cmaxwell(mwcallback)
	ok2 = plane.readMXS(inMxs2)

	planeobject = plane.getObject(planeName);
	scene.addObject(planeobject);

	newMat = scene.createMaterial('default')
	planeobject = scene.getObject(planeName)
	planeobject.setMaterial(newMat)
	if not newMat.read(newM):
	  print ('ERROR: cannot open newM')
  
	# Save modified scene to a new MXS
	outPath = outFolder+'/'+outMxs
	ok = scene.writeMXS(outPath);

if __name__ == "__main__":
	inMxs1 = inputFolder+'/'+scene_name+'.mxs'
	inMxs2 = outFolder+'/'+outMxs
	outFolder = outputFolder
	outMxs = 'new'+'_'+scene_name+'.mxs'
	newM = 'C:/Program Files/Next Limit/Maxwell Render 4/materials database/mxm files/default.mxm'
	add_inf_plane_to_scene(inMxs1,inMxs2,outFolder,outMxs,newM)

################################################################
Will there be a Maxwell Render 6 ?

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