Collect all Materials in scenematerials subnum node

Hey,

I was wondering if there's a less hard coded way of collecting all the materials that are wired into the scenematerials array such as multisubmaterial, blend, CoronaRaySwitchMtl, VRayBlendMtl and so on..

Each of these have different properties to check against for materials but I was hoping to see if it can be done to collect the materials in those slots by checking whether or not it's a material only node or material Array.

Has anyone done this successfully before.

HARDCODED METHOD EXAMPLE #1

crsmMat = meditMaterials[1] = CoronaRaySwitchMtl name:"CoronaRaySwitchMtl"
giMat = crsmMat.giMtl

Returns:

CoronaRaySwitchMtl:CoronaRaySwitchMtl
Material #33:CoronaMtl

HARDCODED METHOD EXAMPLE #2

Mat = multimaterial numsubs:2
if Mat != undefined do objMatSubs = Mat.materialList

Returns:

#Multi/Sub-Object:Multimaterial(Standard:Material #34, Standard:Material #35)
#(Material #34:Standard, Material #35:Standard)

It would be nice if scenematerial array would have a way to get those materials too.

PS.
I thought I could get those materials through the rootScene method but no luck.

w=rootscene[#Scene_Materials] 
for i in w.object do print i

Only returns same as the scenematerials array method. :(

Comments

Comment viewing options

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

You Can Use this Code :

(
	local Allmats_temp = #() , Allmats = #() , AllmatsNames = #() , Allmaps = #() , AllmapsNames = #()
 
	fn getmatsmapsRecurse m array clas: chksup:true = (
		for propName in (getPropNames m) do (
			local prop = getProperty m propname
			if superClassOf prop == clas and findItem array prop == 0 do (append array prop)
			if chksup then if classOf prop == ArrayParameter do (
				for sub = 1 to prop.count where superClassOf prop[sub] == clas do (
	            	if findItem array prop[sub] == 0 do (append array prop[sub])
					getmatsmapsRecurse prop[sub] array clas:clas
				)
			)
		)
	)
	fn CollectMats array c_array = (
		for m in array where m != undefined do (
			if findItem c_array m == 0 do (append c_array m)
			getmatsmapsRecurse m c_array clas:material
		)
		c_array = makeUniqueArray c_array
	)
	fn CollectMaps array c_array = (
		for m in array where m != undefined do (
			getmatsmapsRecurse m c_array clas:textureMap chksup:false
		)
		for m in c_array where m != undefined do (
			getmatsmapsRecurse m c_array clas:textureMap
		)
		c_array = makeUniqueArray c_array
	)
	fn CollectMats_temp sel:false = (
		if sel then (
			Allmats_temp = for obj in selection where not isKindOf obj targetObject and obj.material != undefined collect obj.material
		)
		else Allmats_temp = sceneMaterials
	)
 
	CollectMats_temp() -- CollectMats_temp sel:true ------------------- (to Apply on Selected Objects)
	CollectMats Allmats_temp Allmats
	CollectMaps Allmats Allmaps
	AllmatsNames = for m in Allmats collect m.name
	AllmapsNames = for m in Allmaps collect m.name
 
	/*format "Allmats = %\n" Allmats
	format "Allmaps = %\n" Allmaps
	format "AllmatsName = %\n" AllmatsNames
	format "AllmapsName = %\n" AllmapsNames*/
)

Thanks to @Swordslayer
http://www.scriptspot.com/forums/3ds-max/general-scripting/detect-map-type-diffuse-bump-reflect-etc

barigazy's picture

...

Try to play with getClassInstances fn
http://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_41314BE...

bga

pixamoon's picture

`

Hey,

This should work:

AllMaterials = #()
 
fn FindMaterials m = if m != undefined and Superclassof m == Material do (
	appendifunique AllMaterials m
	for i = 1 to getNumSubMtls m do FindMaterials (getSubMtl m i)
)
 
for m in scenematerials do FindMaterials m
 
print AllMaterials
barigazy's picture

...

Again maybe is smarter way to collect first all unique mats by class from scene materials and then search specific mat. Something like this (just concept)

-- let try with multimaterial
mats = getclassinstances multimaterial target:scenematerials
mtl = --some material ei. multimaterial
uniqueMats = #()
-- appendifunique fn is very slow so we try something like this
if (n = getNumSubMtls mtl) > 0 do
    for i = 1 to n where findItem uniqueMats (m = getSubMtl mtl i) do 
        append uniqueMats m

I did'nt test this but as concept is ok

bga

Comment viewing options

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