Script To Swap Material ID

Hi,

I need help from the codemasters over here. Basically this is what i wanted o do:

1. select all object in scene (all object has a multi/sub mat)
2. swap material id [1] with [5]
3. collapse multi/sub material to standard material

i've tried to search more info on this online but just couldn't figure ou where to start.

Hope there's any good guy greg around here willing to help me. Please!

Comments

Comment viewing options

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

Just to know if it possible

Hi Barigazy,

First of all, thanks you so much for your reply. The 3rd option is actually not a urgent requirement at this moment, just for the sake of learning whether if it is possible.

If it really is possible, then could you kindly write down the syntax so that i can google the syntax and try to make sense of it?

Again, thank you so much.

barigazy's picture

#3

Let's continue

-- Create a box and assigne multisub mtl with 6 standard materials with different diffuse colors and name theses mtls with color name.
-- #1 color names array
colorArr = #("Red","Green","Yellow","Blue","Brown","Orange")
-- #2 multisub materials list (6 standard materials)
multiSubMtlsArr = (for i = 1 to colorArr.count collect (Standard name:colorArr[i] diffuse:(execute colorArr[i])))
-- #3 multisub material
objMaterial = multimaterial name:"BoxMaterial" materialList:multiSubMtlsArr
-- #4 simble object (Box) for recive these material
obj = Box name:"testObject" material:objMaterial
-- now to remove nox material you can use
obj.material = undefined
-- to collaps (change) box material to standard mtl
obj.material = Standard()
-- to collaps box material to first sub material (in this case "Red")
obj.material = obj.material.materialList[1]
-- or 
obj.material = objMaterial.materialList[1]

bga

barigazy's picture

let's start

1.select all object in scene (all object has a multi/sub mat)

You need to consider this:
if you want to swap 1st ID with 5th then you scene object must have minimum five mtlID.
To select all objects that should satisfy the following conditions:

-- filter function for checking material
fn filterFN mat maxID: = mat != undefined and isKindOf mat Multimaterial and mat.materialIDList.count >= maxID
-- I will use in this case "geometry" instead of "objects" collections
sceneObjMtls = for o in geometry where filterFN o.material maxID:5 collect o.material
--No need to select these object for swaping but if you want just run next line
select (for o in geometry where filterFN o.material maxID:5 collect o)

2. swap material id [1] with [5]

-- now you can do:

for mtl in sceneObjMtls do swap mtl.materialList[1] mtl.materialList[5]

And why do you need 3rd options. Why you want to collapse multisub material?

bga

Comment viewing options

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