Multi Material HELP!!!!

Hello one and all,

I am having difficulty with a script that I have written, its supposed to update all the multimaterials sub materials in a scene with materials in a material library. The script works well but fails if a multi material has an empty slot. If any one can help me by getting maxscript to ignore empty slots of a multi material I would be extactic! I cant find anything in the maxscript help files that could possibly do the job!

(Ideally I would like this script to update all of the scenematerials that are either single e.g VrayMtl or sub materials of a multimaterial.)

Script below:

macroScript Fix_Multi_Mat_From_Lib category: "My_Scripts"
(
multiMats = #()
theLibMats = #()

for i = 1 to sceneMaterials.count do -------------------find all the multimats and store them in array
(
if classOf scenematerials[i] == Multimaterial then append multiMats scenematerials[i]
)

FileOpenMatLib() ----choose a material library and make current

for n = 1 to multiMats.count do ---- count the number of multimaterials in the scene
(
for j = 1 to multiMats[n].numsubs do ---- grab a multimaterial and interate through the sub materials
(
for k = 1 to currentMaterialLibrary.count do --- iterate through the current material library
(
if currentMaterialLibrary[k].name == multiMats[n].material[j].name then multiMats[n].material[j] = currentMaterialLibrary[k]
)
print multiMats[n].numsubs
print multiMats[n].name
)

)
)

Comments

Comment viewing options

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

Fixed it! if

Fixed it!

if multiMats[n].material != undefined ......

Comment viewing options

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