Home Technical Talk

[3DSMAX] Maxscript: Replace all similar named (nested) materials with an instanced material.

interpolator
Offline / Send Message
OccultMonk interpolator
I want to replace all materials that share the same name with a single (selected) material instance. Not only the directly assigned materials but also nested materials residing in for instance; multi/sub-materials and corona layered materials and shellack and material blend material. 

The workflow would be: 

1) select a material in the slate material editor to use as instanced replacement.
2) run script, this will replace all materials that have the same name as the selected material in the slate material editor (including nested material).

I have searched for quite a while and found multiple material consolidation scripts, but they do not work as intended.

Replies

  • Swordslayer
    Offline / Send Message
    Swordslayer interpolator
    Something like this should get you started (untested):

    sourceMat = case matEditor.mode of<br>(<br>	#basic : mEdit.getCurMtl()<br>	#advanced : SME.getMtlInParamEditor()<br>)<br><br>updateSceneMaterialLib()<br>mats = #()<br><br>for matType in material.classes do join mats (getClassInstances matType)<br>for mat in mats where mat != sourceMat and mat.name == sourceMat.name do replaceInstances mat sourceMat

  • OccultMonk
    Offline / Send Message
    OccultMonk interpolator
    Swordslayer Amazing, Thanks! Not tested huh. Worked right away :-) I need to try it out further, but that saves me a huge amount of time.
Sign In or Register to comment.