ScriptSpot

Forum topic · Scripts Wanted

Automated Material Script

By JokerMartini · 2010-10-06

Description

If anyone out there feels ambitious, could you write up this material automated script.

It simply takes the selected objects Material and prints it into the Maxscript Listner allowing users to copy the code from there and paste it into scripts for further use.

What's being printed in the Maxscript Listner is the code which creates the material on the currently selected object.

Thoughts? I'd like to know if anyone is interested?

Comments (7)

Graph · 2010-10-08

the function itself doesnt create anything except a stringstream/characterstream wich is returned as a plain old string

so if you feed an arch design mat in youll get that out

was bored after all

Graph · 2010-10-07


(
	
	fn mat2mxs mat =	-- turns a supplied material into a mxs string you can execute to create it /doesnt include maps or arrays atm
	(
		local res
		
		if superCLassOf mat == material do
		(
			res = "" as stringStream
			format "%" (classOf mat) to:res
			
			local propNames = getPropNames mat 
			
			for propN in propNames do
			(
				local propV = getproperty mat propN
				
				if propV != undefined do
				(
					with printAllElements true
					(
						--format "%\t-\t%\t-\t%\n" propN (classOf propV) propV
						case classOf propV of
						(
							string : format " %:\\\"%\\\"" (propN as string) (propV) to:res
							
							color : format " %:%" (propN as string) ([propV.r,propV.g,propV.b,propV.a]) to:res
							
							default : if classOf propV != ArrayParameter do format " %:%" (propN as string) (propV) to:res
						)
					)
				)
			)
		)
		return (res as string)
	)--END mat2mxs FN
	
	local a = mat2mxs meditMaterials[2]
	print a
	
	/*a litle example how you can use the created string*/
-- 	local a = "Standardmaterial shaderType:1 wire:false twoSided:false faceMap:false faceted:false shaderByName:\"Blinn\" opacityType:0 opacity:100.0 FilterColor:[127.5,127.5,127.5,255] opacityFallOffType:0 opacityFallOff:0.0 ior:1.5 wireSize:1.0 wireUnits:0 applyReflectionDimming:false dimLevel:0.0 reflectionLevel:3.0 sampler:0 samplerQuality:0.5 samplerEnable:true samplerAdaptThreshold:0.1 samplerAdaptOn:true subSampleTextureOn:true samplerAdvancedOptions:true samplerByName:\"Adaptive Halton\" UserParam0:0.0 UserParam1:0.0 samplerUseGlobal:true adTextureLock:true bounce:1.0 staticFriction:0.0 slidingFriction:0.0 noExposureControl:false exposureControlInvertSelfIllum:false exposureControlInvertReflection:false exposureControlInvertRefraction:false ambient:[149.94,149.94,149.94,255] Diffuse:[149.94,149.94,149.94,255] Specular:[229.5,229.5,229.5,255] adTextureLock:true adLock:true dsLock:false useSelfIllumColor:false selfIllumAmount:0.0 selfIllumColor:[0,0,0,255] specularLevel:0.0 glossiness:10.0 Soften:0.1 Ambient_Color:[149.94,149.94,149.94,255] Diffuse_Color:[149.94,149.94,149.94,255] Specular_Color:[229.5,229.5,229.5,255] Self_Illumination:0.0 Self_Illum_Color:[0,0,0,255] Specular_Level:0.0"
-- 	if a != undefined do meditMaterials[13] = execute a
	
)

if anyOne cares you can also format it out to a verbatim string or use directly (dunno why one would do the latter) but then you gotta lose the extra formating for string classes
to lazy to build in handling for arrays but if one needs it its simple to implement
after adding array handling textureMaps will be quite simple too

have phun

Looks good.

JokerMartini · 2010-10-07

Works pretty well. It seems though everytime I run the script it create an Arch Design MXS.

fajar · 2010-10-07

you can try this script although it doesnt print mat prop in listener

Anubis · 2010-10-06

Hi John,
Im not understand... did you looking for script that convert the material to mxs-code? And then execute this code to recreate the same material with all its settings?

Correct,

JokerMartini · 2010-10-06

That is exactly what I want Anubis. A script that coverts a material to mxs code. Then recreates the same material when executed.