ScriptSpot

Forum topic · Scripts Wanted

(Help needed) SelectionMtls to MultiSubMat - ID count error

By tarsonis · 2015-07-08

Description

Hey there,

as I was looking for a material to MultiSubMat collector script I found this one below. It works like I hoped and puts the materials of the selected objs in the subslots but only with obj counts below 11.
After the 11 material the multisub.matrialIDList doesn't count further above 12 and I get the dublicated material ID error.
Was trying some IDList[] commands but my script knowledge is pretty basic. So i hope for help. I think its an command bug with the mmtl itself and its standard 10 material slots.


(

if selection.count != 0 do 
(
	mmtl = multimaterial name:"SelectionMtls"
	mmtl.materialList = for i = 1 to selection.count where selection[i].material != undefined collect
	(
		addModifier selection[i] (Materialmodifier materialID:i)
		selection[i].material
	)
	--add new material to material editor (first slot)
	selection.material = meditMaterials[1]= mmtl
)

)
Attachments
Comments (2)

barigazy · 2015-07-09

Try this fn

fn makeSelectionMtl mtlname: slot: = if selection.count > 0 do
(
node = dataPair objs:#() mtls:#()
for o in selection where o.mat != undefined do (append node.objs o ; append node.mtls o.mat)
if node.objs.count > 0 do
(
meditMaterials[slot] = multimaterial name:mtlname materialList:node.mtls materialIDList:(#{1..node.mtls.count} as array)
for i = 1 to node.objs.count do
(
node.objs[i].mat = meditMaterials[slot]
addModifier node.objs[i] (Materialmodifier materialID:i name:("Material_#" + i as string))
)
)
)
makeSelectionMtl mtlname:"SelectionMtls" slot:1

tarsonis · 2015-08-04

Wow, thanks. Great. Was in vacation so sorry for the late response. Works but in one particular scene object it crashes max, because it adds 800 of material dublicates for each obj that has the same material.

Is it possible to write an condition that it skips adding the same materials over and over and accordingly sets the material IDs correct?

In my particular scene I got a multisub with 800 submaterials which consist 9 materials the rest are dublicates. Clean Multisub crashes max.