ScriptSpot home

Forum topic · General Scripting

MaxScript to batch render with automatic texture changes

By worwhite · 2012-12-12

Description

Hi!

I have a scene with a single cube, and I need to render (and save) pictures of this scene hundreds of times, each with a different texture (diffuse bitmap) on the cube. The bitmap textures are numbered from 001.bmp to 699.bmp

So basically I need a script to automatically change the diffuse bitmap texture of a single material (Material 01), then render the scene to an image file, and repeat for all the textures.

Is it possible to write such a script? If yes, would anybody be kind enough to write it, or at least point me to a resource that might help?

Thanks in advance :)

Comments (18)
jbrckovic

Same material

Hi Miauu, this script is exactly what we'd need for few hundreds of renders. I'm having a trouble with Standard material since I'm using Corona. Is there a way to use existing material, and only change diffuse map? Thanks

Reply to jbrckovic
miauu

.

Hi!
Check if this works as you want:




(
	global rol_worwhite
	try(destroyDialog rol_worwhite)catch()
	rollout rol_worwhite "miauu"
	(
		local matDir = undefined
 
		button btn_browse "Select folder with textures"
		button btn_render "RENDER" enabled:false
 
		on btn_browse pressed do
		(
			dir = getSavePath caption:"Select folder with textures"
			if dir != undefined do
			(
				matDir = dir
				btn_browse.tooltip = matDir
				btn_render.enabled = true
			)
		)
 
		on btn_render pressed do
		(
			local curObj = selection[1]
			local matFiles = getFiles (matDir + "\\*.bmp")	--	get only BMP files
			renderSceneDialog.close()
			local originalOutPath = rendOutputFileName
			for m = 1 to matFiles.count do
			(
-- 				curObj.material = standardMaterial  diffuseMap: (Bitmaptexture fileName:matFiles[m]) showInViewport:true
				curObj.material = CoronaMtl  texmapDiffuse: (Bitmaptexture fileName:matFiles[m]) showInViewport:true
				outputPath = (getfilenamepath originalOutPath) + ( getFilenameFile(filenamefrompath originalOutPath)) + "_" + (m as string) + "_"  + (getFilenameType originalOutPath)
				rendOutputFileName =  outputPath
				rendSaveFile = true
				--	disable virtual frame buffer
				rendShowVFB = false
				max quick render
			)
		)
 
	)
	createdialog rol_worwhite
)
jbrckovic

Same material

Hi Miauu, this script is exactly what we'd need for few hundreds of renders. I'm having a trouble with Standard material since I'm using Corona. Is there a way to use existing material, and only change diffuse map? Thanks

kishore

How can I apply it to multiple objects

Hi, your solution works for single object, but I wanted to apply the same texture to multiple objects in the scene

Reply to kishore
miauu

.

Replace this lines:


on btn_render pressed do
		(
			local curObj = selection[1]

with this:


on btn_render pressed do
		(
			local curObj = selection as array
Reply to miauu
kishore

How to add bump maps to it

After some struggle I figured it out that I have to do the way you specified it. How do I add bump maps path also to it.

thanks for your time

Reply to kishore
miauu

.

replace this:


curObj.material = standardMaterial  diffuseMap: (Bitmaptexture fileName:matFiles[m]) showInViewport:true

with this:


curObj.material = standardMaterial  diffuseMap:(Bitmaptexture fileName:matFiles[m]) bumpMap:(Bitmaptexture fileName:matFiles[m]) showInViewport:true
nithin

miauu

hello sir ,

Can u makes this script working with 2 objects and separate texture folders for 2 objects ...

thanks ...

miauu

Hi, Branko!
Regards from BG :)

Branko Živković

hi Kostadin.
In the same time we are post comment :)
Regards!

Looks useful

That looks useful. I'm not sure it does what I need in this case (anyway I already got what I needed), but it might come in really handy in future. Thanks!

Edit: Just something funny - I didn't add a subject for the comment at first, and it automatically took the first few words of the comment, which gave:

"That looks useful. I'm not"

LOL

Reply to worwhite
Tony

How did you slove it?

Hello, its been i while but im looking something similar to you, and i would like to know how you face it and the solution to it and if you might be able to share it with me? thanks

miauu

Try this script:( global

Try this script:


(
	global rol_worwhite
	try(destroyDialog rol_worwhite)catch()
	rollout rol_worwhite "miauu"
	(
		local matDir = undefined
		
		button btn_browse "Select folder with textures"
		button btn_render "RENDER" enabled:false
		
		on btn_browse pressed do
		(
			dir = getSavePath caption:"Select folder with textures"
			if dir != undefined do
			(
				matDir = dir
				btn_browse.tooltip = matDir
				btn_render.enabled = true
			)
		)
		
		on btn_render pressed do
		(
			local curObj = selection[1]
			local matFiles = getFiles (matDir + "\\*.bmp")	--	get only BMP files
			renderSceneDialog.close()
			local originalOutPath = rendOutputFileName
			for m = 1 to matFiles.count do
			(
				curObj.material = standardMaterial  diffuseMap: (Bitmaptexture fileName:matFiles[m]) showInViewport:true
				outputPath = (getfilenamepath originalOutPath) + ( getFilenameFile(filenamefrompath originalOutPath)) + "_" + (m as string) + "_"  + (getFilenameType originalOutPath)
				rendOutputFileName =  outputPath
				rendSaveFile = true
				--	disable virtual frame buffer
				rendShowVFB = false
				max quick render
			)
		)
		
	)
	createdialog rol_worwhite
)

The RENDER button will be ebanled when you select the valid folder(in this folder you have to have the texture that you want to be added to the cube in BMP format).
Open Render Setup dialog(hotkey F10) and select the width and height of the rendered images, the output path, the base name for rendered images and so on.
Select the cube(or any other object that you want to use).
Press the RENDER button.
The script save rendered images in the folder, specified in the Render Setup Dialog.
The script will render the cub

Reply to miauu
worwhite

Brilliant! Thanks!

This worked BRILLIANTLY! I loved the select folder option and simply using the number of .bmp files too. Thanks!!!

Reply to miauu
kishore

How can I apply it to multiple objects

Hi, your solution works for single object, but I wanted to apply the same texture to multiple objects in the scene

Reply to miauu
Tony

i have a question?

hello, i would like your help, i need to know how i can use this but instead change the folder texture and the texture, just after finish the render select an apply the next material and render and save and with all the material i have in the material browser.

Thanks.