assign files from folder to material

Hi,

sorry for my bad english, it´s not my native. I need your help. i need a script todo the following.

i have 5 folders with around 40-50 textures, in every folder is a seperate file too, this file is used as bump map. I have a objectgroup in the scene. I build this script, parts are here from the forum, thx miauu

(
	global rol_worwhite
	try(destroyDialog rol_worwhite)catch()
	rollout rol_worwhite "miauu"
	(
		local matDir = undefined
		local bumpFile = undefined
 
		button btn_browsebump "select bump map"
		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_browsebump pressed do
		(
			file = getOpenfileName caption:"select bump map"
			if file != undefined do
			(
				bumpFile = file
				btn_browsebump.tooltip = bumpFile
				btn_render.enabled = false
			)
		)
 
		on btn_render pressed do
		(
			local curObj = getCurrentSelection()
			local matFiles = getFiles (matDir + "\\*.jpg")
			local scenename = getFilenameFile maxfilename
			renderSceneDialog.close() 
			selectedCamera = viewport.getCamera()
			local originalOutPath = rendOutputFileName
			for m = 1 to matFiles.count do
			(
				curObj.material = standardMaterial  diffuseMap: (Bitmaptexture fileName:matFiles[m]) showInViewport:true
				texturename =  ( getFilenameFile matFiles[m])
				cameraName = selectedCamera.name
				outputPath = (getfilenamepath originalOutPath) + ( getFilenameFile(filenamefrompath originalOutPath)) + "_" + scenename + "_" +  cameraName + "_" + texturename + "_"  + (getFilenameType originalOutPath)
				rendOutputFileName =  outputPath
				rendSaveFile = true
				rendShowVFB = false
				max quick render
			)
		)
 
	)
	createdialog rol_worwhite
)
/<code>
 
what i do, i select the object and i point to the folder, where the textures are and 3dsmax render each frame with the texture. Put the cameraname, filename and texture name into the filepath. That works great so far. 

The thing is now, i want to add the textures as Multi/Sub object, every texture has it´s own ID and add to the material the bump map. So every bump map has it´s own 30-40 textures. After this, i need the used bumpmap and the used texture and the name of the selected object as filename.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Graph's picture

feel free to adapt

feel free to adapt this:

(
	local objsToSwitchTextures = selection as array;	--define the objects that will have their textures replaced
 
	local textureFolder = @"C:\Users\Graph\Desktop\Neuer Ordner (2)\";	--define the folder to search for the replacement-textures
 
	local fileType = @"*.jpg";	--define the fileType of the textures to use
 
	local mapSlotName = "DiffuseMap";	--define the material's map slot to assign the new textures to
 
	local printMapSlotNames = true;	--if set to true the material's map slot Names are gonna be printed to the listener
 
	/* ************************ */
	/* ************************ */
	/* ************************ */
 
	fn getMatMapProps mat =
	(
		if mat != undefined AND superClassOf mat == material do
		(
			local str = stringstream ""
			showproperties mat to:str
			str = filterstring (str as string) "\r\n"
 
			local nonCollClasses = #(integer, float, array, arrayparameter, booleanclass, color, material)
 
			str = for prop in str where findString prop "alias" != undefined OR findString prop "map" != undefined collect
			(
				local prop2 = 0
				prop = replace prop 1 (findString prop ".") ""  --remove whiteSpace before prop
				prop = substring prop 1 ((findString prop " ")-1) --cut out only the prop
				local firstLetter = toUpper (substring prop 1 1) --get first letter in uppercase
				prop = replace prop 1 1 firstLetter --replace first letter with uppercase
				if hasProperty mat prop do --check if the generated prop string exists at all
				(
					prop2 = getProperty mat prop --get the value
				)
				if findItem nonCollClasses (classOf prop2) == 0 AND findItem nonCollClasses (superClassOf prop2) == 0 AND prop.count > 6 then prop else dontcollect --sort out and return the valid props to collect
			)
			return str
		)
	)--END getMatMapProps FN
 
	local textureFiles = getFiles (textureFolder + fileType) ;
	local isRndNameSet = rendOutputFilename.count >=5;
	local rendFilename = copy rendOutputFilename;
 
	if objsToSwitchTextures.count > 0 then
	(
		if textureFiles.count > 0 then
		(
			for texture in textureFiles do 
			(
				for obj in objsToSwitchTextures do
				(
					if obj.material != undefined do 
					(
						if printMapSlotNames do
						(
							local matMapProps = getMatMapProps obj.material;
 
							local str = obj.material.name + " | " + (classOf obj.material) as string + "\r\n";
 
							for slot in matMapProps do 
								str += "\t" + slot + "\r\n";
 
							print str;
						)
 
						if isProperty obj.material mapSlotName then
						(
							local tex = bitmaptex fileName:texture;
							setProperty obj.material mapSlotName tex;
						)
						else
						(
							format "Cannot find mapSlotName \"%\" in material % : %\tPlease change the code in Line #9\r\n" mapSlotName obj.material.name obj.material 
						)
					)
				)
 
				if isRndNameSet then
				(
					local fName = (getFilenamePath rendFilename) + (getFilenameFile rendFilename) + "_" + (getFilenameFile  texture) + (getFilenameType rendFilename);
					rendOutputFilename = fName;
					format "File % rendered\r\n" fName;
				)
				else
				(
					local fName = textureFolder + ("batchMatReplace_" + (getFilenameFile  texture)  + ".png");
					rendOutputFilename = fName;
					format "File % rendered\r\n" fName;
				)
 
				render outputfile:rendOutputFilename;
			)
		)
		else
		(
			Messagebox "No Textures where found\r\nMake sure to propeprly define the TextureFolder AND FileType in lines #4 && #6";
		)
	)
	else
	(
		Messagebox "You didn't select any Objects to replace Textures on";
	)
 
	rendOutputFilename = rendFilename;
)

Raphael 'Insanto' Steves
http://Graph.Net84.Net

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.