ScriptSpot

Forum topic · General Scripting

De-Instance materials

By David_Lee · 2013-06-30

Description

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 (5)

miauu · 2013-07-01

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 · 2013-07-01

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

miauu · 2013-07-01

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. :)

It works!!

David_Lee · 2013-07-03

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()
		)
	)
)

I think I found a sloution:

miauu · 2013-07-01

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