De-Instance materials

I need to rename all the SubMaterials in scene adding a "Sub_" prefix.
To doing this, I wrote a simple script:

for o in sceneMaterials do
(
        if (classof o == Multimaterial) then 
	(
		for i in o.materialIdList do
		(
			try
			(
				subo = o[i]
				subo.name = "Sub_"+subo.name
			)
			catch()
		)
	)
)

But the problem is that sometimes, a submaterial is an instance of another material in scene and if I rename the submaterial, the master material is renamed too.
So, how can I check if the submaterial is an instance and, if it is, make it unique and then rename it?

Someone could help me, please?

Thanks,
David

Comments

Comment viewing options

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

To find all instances of a

To find all instances of a material check this

To make material unique see what is written in maxscript help file:

assignNewName <material>

Modifies the name of the specified material to make it unique. The name is of the form "Material #1" where the number is incremented as required to make ensure it’s unique.

David_Lee's picture

Tried using assignNewName,

Tried using assignNewName, but it doesn't make the submaterial unique. It rename both submaterial and master material as "Material #n".

miauu's picture

I think I found a sloution:

The first slot in Material Editor is a multisub. All submaterials are instances of subMat[1]

-- the first slot is multisub mterial. All submat-s are instances of submat[1]
msm = meditmaterials[1]
-- get the second submat
-- create a copy
tmp = copy msm[2]
-- assign the copy back 
msm[2] = tmp
miauu's picture

Same behaviour here. Maybe we

Same behaviour here. Maybe we don't know how to use it. I started a thread in cgtalk. Hope someoane to gives us the answer. :)

David_Lee's picture

It works!!

Thanks a lot miauu!!
I know how to use it, I have the answer! :)

for o in sceneMaterials do
(
        if (classof o == Multimaterial) then 
	(
		for i in o.materialIdList do
		(
			try
			(
				subo = o[i]
				tmp = copy subo
				o[i] = tmp
				o[i].name = "Sub_"+subo.name
			)
			catch()
		)
	)
)

Comment viewing options

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