User avatar
By seghier
#399767
Hello
The script worked fine with old versions 3 and 4 , but don't work with v5, the scenes exported empty with the new material only.
What's wrong here ? i hope it is not a bug :)

Code: Select all
################################################################
# Read all MXS in a folder, prints some info.
################################################################

from pymaxwell5 import *
import os

def MXMchangeMaterialFromMXM(mxsFolder,outPath):

	mxslist = getFilesFromPath(mxsFolder,'mxs')
	scene = Cmaxwell(mwcallback_cb)

	for mxs in mxslist:
		#print str(mxs)
		name = os.path.splitext(mxs)[0]
		print name
		scene.readMXS(mxs)
		newMatName, descr, im, ok = CmaxwellMaterial.getMxmInfo(newMatPath)
		newMat = scene.createMaterial(newMatName)
		newMat.read(newMatPath)
		
		it = CmaxwellObjectIterator()
		obj = it.first(scene)
		
		while not obj.isNull():

			# update object material

			print('Object: '+obj.getName()[0])
			objMat = obj.getMaterial()[0]
			if not objMat.isNull():
				print('  Material: '+objMat.getName())
				if objMat.getName() == oldMatName:
					obj.setMaterial(newMat)
					print('  UPDATED -> '+newMatName)

			# update triangle group material

			itGroup = CmaxwellObjectTrianglesGroupIterator()
			group = itGroup.first(obj)

			while not group.isNull():
				print(' Group: '+group.getName())

				# get group material from the 1st triangle of the group

				triangles = group.getTriangles()
				groupMat = obj.getTriangleMaterial(triangles[0])[0]
				print('  Material: '+groupMat.getName())

				if groupMat.getName() == oldMatName:
					group.setMaterial(newMat)
					print('  UPDATED -> '+newMatName)

				group = itGroup.next()

			obj = it.next()

		outputpath = outPath+'/'+name+'_updated.mxs'
		if not scene.writeMXS(outputpath):
			print('ERROR: cannot save '+outputpath)
			return 0
	
	return 1
			
	#return 1;

if __name__ == "__main__":
	oldMatName = 'plane'
	newMatPath = 'C:/maxwell tool v5/materials/leather.mxm'
	mxsFolder = 'C:/maxwell tool v5/animation'
	outPath = 'C:/maxwell tool v5/output'
	MXMchangeMaterialFromMXM(mxsFolder,outPath)
New podcast - CG Talks

Hi guys! We've just finished the first season of […]

Thanks, Luis, appreciated. It looks like industria[…]

That looks like a low bpc (bits per channel) norma[…]

Fully working plugin for C4D

When you will be working on it please try to keep […]