Convert Arch & Design To Standard Materials 3dsmax (2020-2021)

3dsmax, maya, afx 3d, programming, math, conservation, model making, rigging
Post Reply
darknkreepy3#
Site Admin
Posts: 253
Joined: Tue Oct 27, 2009 9:33 pm

Convert Arch & Design To Standard Materials 3dsmax (2020-2021)

Post by darknkreepy3# »

I found this script online from user BRADOWADO and he did a great job as a "noob" (not) writing this maxscript. It worked in Forest Pro examples to remove the Arch & Design materials (no idea what rendering bugs will happen dumping down to standard). Time to learn how to do this as well and maybe pop stuff to Arnold as well from A & D or standard etc. 10/10 to BRADOWADO.

https://supercala.net/phpBB3/_files/arc ... adowado.ms

Code: Select all

(
global MaterialConversionGUIRollout

global supportedNonStandardMaterialClasses = #
(
	Arch___Design__mi,
	Architectural,
	Multimaterial
)

fn ConvertMaterialToStandard mat =
(
	format "Starting conversion of: % \n" mat
	newStandardMaterial = undefined
	newMaterialName = undefined
	newDiffuse = undefined
	newDiffuseMap = undefined

	--translate Mental Ray Arch & Design material properties to Standard Material properties
	if (classof mat == Arch___Design__mi) then
	(
		format "                Converting Arch___Design__mi material properties: % \n" mat
		if(mat.diff_color != undefined) 			then ( newDiffuse 		= mat.diff_color )
		if(mat.diff_color_map != undefined) 	then ( newDiffuseMap 	= mat.diff_color_map ) 
		
	)
	
	--translate Architectural material properties to Standard Material properties
	else if (classof mat == Architectural) then
	(
		format "                Converting Architectural material properties: % \n" mat
		if(mat.diffuseColor != undefined) 		then ( newDiffuse 		= mat.diffuse )
		if(mat.diffuseMap != undefined) 		then ( newDiffuseMap 	= mat.diffuseMap )
	)
	
	--Create the standard material
	newStandardMaterial = StandardMaterial name: mat.name
	if(newDiffuse != undefined) 					then ( newStandardMaterial.diffuse 		= newDiffuse )
	if(newDiffuseMap != undefined) 			then ( newStandardMaterial.diffusemap 	= newDiffuseMap )
	newStandardMaterial.showInViewport = true
	
	format "                    Converting % material to % material \n" mat newStandardMaterial
	replaceinstances mat(newStandardMaterial)	--replace the current material instance with the new standard material
)

fn ConvertAllMaterials = 
(
	allNonStandardMaterials = #()
	
	for allMaterialClasses in material.classes do 
	(
		for mat in (getClassInstances allMaterialClasses processAllAnimatables:true) do
		(
			if (classof mat != Standard) then
			(
				append allNonStandardMaterials mat
			)
		)
	)
	
	for nonStandardMaterial in allNonStandardMaterials do
	(
		format "Found non standard material: % \n" nonStandardMaterial
		nonStandardMaterialClass = classof nonStandardMaterial
		format "The class of this material is: % \n" nonStandardMaterialClass
		
		for supportedMaterial in supportedNonStandardMaterialClasses do
		(
			format "    Checking if % material class matches %. \n" nonStandardMaterialClass supportedMaterial
			if(classof nonStandardMaterial == supportedMaterial) then
			(
				if (classof nonStandardMaterial == Multimaterial) then 
				(
					format "        Found multimaterial: % \n" nonStandardMaterial
					-- This is a multi-sub material, so loop through all submaterials
					for i in nonStandardMaterial.materialIdList do 
					(
						submat = nonStandardMaterial[i]
												
						if (classof subMat == Multimaterial) then --Nested Multimaterial
						(
							format "            Found nested sub material: % \n" subMat
							for i in subMat.materialIdList do 
							(
								nestedSubMat = subMat[i]
								
								if(classof nestedSubMat != Standard) then
								(
									if(nestedSubMat == undefined) then
									(
										--skip the material slot if it's undefined, and move on to check for valid materials
									)
									else
									(
										format "            Converting nested sub material: % \n" nestedSubMat
										ConvertMaterialToStandard nestedSubMat
									)
								)
							)
						)
						else
						(
							if(classof subMat != Standard) then
							(
								if(subMat == undefined) then
								(
									--skip the material slot if it's undefined, and move on to check for valid materials
								)
								else 
								(
									format "            Converting sub material: % \n" subMat
									ConvertMaterialToStandard subMat
								)
							)
						)
					)
				)
				else
				(
					format "        Converting material: % \n" nonStandardMaterial
					ConvertMaterialToStandard nonStandardMaterial
				)
			)
		)
	)
	print "Finished conversion of non-standard materials to standard materials."
)

fn DeleteHiddenObjects =
(
	hiddenObjects = for obj in objects where obj.isHidden collect obj
	if hiddenObjects.count > 0 then
	(
		/*
		for obj in hiddenObjects do 
		(
			format "Deleting hidden object: %\n" obj
			delete obj
		)
		*/
		delete hiddenObjects
		print "Finished deleting hidden objects."
	)
	print "No hidden objects found. Nothing deleted."
)
--GUI
try(DestroyDialog MaterialConversionGUIRollout) catch()

rollout MaterialConversionGUIRollout "Material Conversion" width:200 height:300
(
	--GUI Elements
	GroupBox testingGroup "Testing" pos:[5,5] width:195 height:295
	button ConvertAllMaterialsButton "Convert Materials" pos:[5,5] width:190 height:25
	button DeleteHiddenObjectsButton "Delete Hidden Objects" pos:[5,35] width:190 height:25
		
	--GUI Button Handlers
	on ConvertAllMaterialsButton pressed do 
	(
		ConvertAllMaterials()
	)
	
	on DeleteHiddenObjectsButton pressed do 
	(
		DeleteHiddenObjects()
	)
)

CreateDialog MaterialConversionGUIRollout
)
Post Reply