All posts related to V3
#385704
I'm not familiar with scripting, but I wonder if I could replace an object in a MXSfile for an MXSreference by using a script. I want to know if this would be posible to do in a batch for an animation.

Since Blender doesn't support the use of MXSreferences I could use a placeholder in my scene. After exporting the animation it would be nice to run a batch script to open the MXS sequence and replace an object for a MXSreference. This way the exported sequence can be small in file size, for example a fly-through animation where only the camera is animated and a MXSreference is loaded.

Any ideas?
Last edited by Hillmeister on Mon Mar 16, 2015 12:38 pm, edited 1 time in total.
#385720
Hello
i am not sure if that work for animation
when you render a scene than stopped the render and made change in maxwell studio
than render again ; the new render detect the change
can you try to stop your render and change the objects you want by mxs reference than re-render ?
give it a try ; i never tried animation before
-------------------------------
maxwell render used tmp mxs file ; you must choose the new scene saved in scene file
#385726
My workflow for stills is a bit like you say Seghier.

I export a model (in my case a ship) without anything else from Blender to an MXS. This MXS is added to a scene through a MXSreference. The scene contains everything else, environment, camera's, water, landscape, etc.
When the model is updated and exported with Blender, the MXSref is updated in the scene. Now this works very well, especially when you take into account that our scene's sometimes have MXSreferences coming from different softwares like Rhino, Revit and 3DsMax. (Maxwell is the perfect glue :D )

Since Blender doesn't (yet?) supports MXSrefs, it's not possible to load those MXSrefs from other packages to make an camera-path animation for example and then export the animation straight from Blender. So when a script could replace certain objects in a MXS sequence this could be a nice work around. To do this manually for every animation frame would be very tedious.

Sorry this post is getting to Blenderish, it might have been better to drop it at the Blender section. I was hoping some non-Blender MWscripters could give some advice. :mrgreen:
User avatar
By Brany
#385787
Try this script:
Code: Select all
import pymaxwell as mw
import os

def replaceObjectWithMxsRef(scene,objName,mxsPath):
	# Get object to replace
	objToReplace = scene.getObject(objName)
	if objToReplace.isNull():
		# If not exists, return
		return (False,'')
	# Create reference MXS object
	objRef = scene.createReferencedObject('ref',mxsPath);
	if objRef.isNull():
		# If cannot be created, return
		return (False,'')
	# Delete object to replace
	objToReplace.free()
	# Return True, and MXS ref object name. It can change if there is 
	# an object with the same name we want to set to the mxs ref object
	return (True,objRef.getName()[0])

if __name__ == "__main__":
	path = 'D:/SAMPLES/maxwell/3.1.0.0/vargas/animation'
	objName = 'group19_27'
	mxsRefPath = 'D:/SAMPLES/maxwell/3.1.0.2/cube/cube.mxs'
	savePath = 'D:/SAMPLES/maxwell/3.1.0.0/vargas/animation/ouput'
	# create output path
	if not os.path.exists(savePath):
		os.mkdir(savePath)
	# Get all filenames of MXS files in the path
	mxsList = getFilesFromPath(path,'mxs')
	for mxs in mxsList:
		# for each file, create a MXS scene and read it from disk
		scene = mw.Cmaxwell(mw.mwcallback)
		if not scene.readMXS(path+'/'+mxs):
			print('Cannot read: '+path+'/'+mxs)
			continue
		# replace object 'objName' whith mxs reference in 'mxsRefPath'
		if not replaceObjectWithMxsRef(scene,objName,mxsRefPath):
			print('Error replacing object')
		# save scene. not overwritting
		if not scene.writeMXS(savePath+'/'+mxs):
			print('Error saving scene to: '+savePath+'/'+mxs)
		scene.freeScene()
	print('End')
Of course, yo have to change the paths and object name ;)
#385852
Hi Brany,

Sorry for this late reply, I will be checking this out soon!

Thanks!
#385899
Hi Brany,

I just checked the script and it works great. I tried a simple scene and will try something more interesting later on.

Thank You so much!!

ok thanks for explaining. actually I do copy the T[…]

Sketchup 2026 Released

Fernando wrote: " Now that Maxwell for Cinema[…]

Hello Gaspare, I could test the plugin on Rhino 8[…]

Hello Blanchett, I could reproduce the problem he[…]