Detect scene materials with real-world scale maps

Hello,
I am looking for some piece of script which will select all scene objects with materials contains real-world scale maps.

Thank you very much for help.

Comments

Comment viewing options

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

try

function collectRealWorldMats savetoFile:False = (
	rwMats = materialLibrary()
	for mat in sceneMaterials do (
		local maps = getproperty mat "Maps"
		for m in maps where superclassof m == textureMap do (
			try (if getproperty m.coords "realWorldScale" != undefined do (if m.coords.realWorldScale do (appendifunique rwMats mat))) catch()
		)
	)
	if rwMats.count > 0 do (
		if savetoFile then (
			-- save these materials to C:\Users\User\AppData\Local\Autodesk\3dsMax\2013 - 64bit\ENU\temp\realWorldMats.mat
			local rwMatsFile = getdir #temp + "\\realWorldMats.mat"
			saveTempMaterialLibrary rwMats rwMatsFile
		) else (for m in rwMats do print m.name) -- or simply output to listener
		-- select objects with these mats
		objs = #(); for m in rwMats do (for o in objects where o.material == m do append objs o)
		select objs
	)
	rwMats
)
 
collectRealWorldMats()
-- or if you want to save to realWorldMats.mat
-- collectRealWorldMats savetoFile:true

Because it use sceneMaterials, the file needs to be saved before running this script. Edit: Now it uses "textureMap" instead of "BitmapTexture"

Rivanoor Bren
https://rivanoor.info

arch3d's picture

Thank you very much!

But i got error in line 4:
-- Unknown property: "maps"

Script will run with CoronaBitmap as well?

id_ivan's picture

--

I forget that people dont use standardMaterial anymore. LOL.
Yes this works for coronaBitmap.
I change collection using object materials instead of sceneMaterials.
Will not work on any material class other than vrayMtl, CoronaMtl and standardMaterial.

(
	function collectRealWorldMats = (
		local mats = #(), rwMats = #()
		for o in objects where o.material != undefined do appendIfUnique mats o.material
		for mat in mats do (
			case classof mat of (
				standardMaterial:(
					local maps = getproperty mat "Maps"
					for m in maps where superclassof m == textureMap do (
						if isproperty m.coords "realWorldScale" and m.coords.realWorldScale do (appendifunique rwMats mat)
					)
				)
				default: (
					for m=1 to mat.numsubs do (
						if classof mat[m] == SubAnim and superclassof (tM = mat[m].object) == textureMap do (
							if classof mat == coronaMtl and isproperty mat[m] "realWorldScale" and mat[m].realWorldScale do appendifunique rwMats mat
							if classof mat == VrayMtl and isproperty mat[m].coords "realWorldScale" and mat[m].coords.realWorldScale do appendifunique rwMats mat
						)
					)
				)
			)
 
		)
		rwMats
	)
	mats = collectRealWorldMats()
	objs = #()
	for m in mats do (for o in objects where o.material == m do appendIfUnique objs o)
	select objs
)

Rivanoor Bren
https://rivanoor.info

arch3d's picture

Thanks again

Sorry for late respond but i had no time to tests
If i save scene and try to use script nothing happens:(

Comment viewing options

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