How to find instanced material in Material Editor?


#1

Is there a way to find all instanced materials in Material Editor? I searched the net and maxscript help file, but with no success. Any ideas?


#2

what is instanced? do you mean all instances of some material?


#3

Yes. In material editor I have slot1 with MultiSubobject material with 5 sub materials. In slot5 I have another MultiSubobject material with 10 sub materials. The subMat4 of slot5 is instance of subMat2 of slot1. In the Material Editor the Make Unique buttons become enabled and I can press it, but how to find that the subMat4 of slot5 is instance of subMat2 of slot1 via maxscript. Using the subMaterial names is enaugh or not, because in the MultiSubobject material I can have two different subMaterials with the same names, but one of them is instance and the other one is not?


#4

do you need all instances for all materials, or just for a specified one?


#5

I have to know if the material is instance or not. The reason is that the script have to change the Diffuse color of the materials, and if I loop through all materials the instances will have color correction multiple times. So the loop have to skip the instances. I think that if I can create an array with the all instances of specific material then I can change the diffuse color only for one of the materials in the array and the other materials will receive the new color. Then for the second material, if it is not in the first array, I will check if this material have instances and will build new array if it have, and so on. If the material not have instances then the there will be no need of the array that will holds all onstances.


#6

ok… it’s easier:

fn findMaterialInstances mat target:meditmaterials = 
(
	mats = getclassinstances (classof mat) target:target astrackviewpick:on
	for t in mats where t.anim == mat collect
	(
		format "parent:%
	id:%
" t.client t.subnum
		t
	)
)
resetmaxfile #noPrompt 
meditmaterials[1] = multimaterial materiallist:#(undefined, meditmaterials[3]) 
meditmaterials[2] = multimaterial materiallist:#(undefined, undefined, meditmaterials[3], meditmaterials[3]) 

findMaterialInstances meditmaterials[3]

#7

Works in max2013, but in max2009 gives this error:

-- Error occurred in findMaterialInstances(); filename: ; position: 111
--  Frame:
--   mat: 03 - Default:Standard
--   target: #meditMaterials()
--   called in anonymous codeblock
--  Frame:
-- Unable to convert: #meditMaterials() to type: MaxObject

#8

in max 2009 you have to use meditMaterials’s reference target


#9

Thank you.
:slight_smile:


#10

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.