Need a way to replace the sub-object ID1 of all selected objects with 1 material

Hey all!

I have multiple objects in a scene, each with their own materials. Within each of those materials are 2 sub-object materials (ID#1 for left, and ID#2 for right).

I am looking for a quick way to select specific objects and replace it with a new material to all of the ID#1's (which are currently all unique).

Right now, I am manually doing this in the Slate Material Editor by dragging each individual material into the view, then linking the new material to each sub-object material.

I would be extremely grateful for any help to automate, or speed up this process! Thanks in advance :)

Trumap

Comments

Comment viewing options

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

Anyone help please? *bump*

Anyone help please? *bump*

barigazy's picture

...

You can use this function

fn replaceMtls sourcemat nodes id: = 
(
	if isKindOf sourcemat material and nodes.count > 0 do
	(
		for o in nodes where o.mat != undefined and isKindOf o.mat Multimaterial do 
			if finditem o.mat.materialIDList id!= 0 do o.mat.materialList[id] = sourcemat
	)
)

Function arguments are:
*sourcemat* - new material for replacement
*nodes* - selection of objects which sub-material (in your case #ID1)
need to be replaced with *sourcemat* material
*id* - is ID number

Now how to use it. Run the code above first in maxscriptListener or Editor.
Select all object which submaterial need to be changed.
Let's say your *sourcemat* is in 15 slot in Material editor.
In maxscript listener write and execute this line of code

replaceMtls meditMaterials[15] selection id:1

barigazy

trumap's picture

Anyone help please? *bump*

Anyone help please? *bump*

Comment viewing options

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