thibaud-d of BlenderBox
10/10/2014 - 5:05 AM

For all objects in the current Blender scene, search for materials named something like MATERIAL.001, MATERIAL.002... and replace by a mater

For all objects in the current Blender scene, search for materials named something like MATERIAL.001, MATERIAL.002... and replace by a material named MATERIAL (if available)


# Fix materials.
# For all objects in the current Blender scene, search for materials named 
# something like MATERIAL.* by a material named MATERIAL (if available).
# Created by T.E.A de Souza

import bpy

s=bpy.context.scene

def replaceMaterial(slot,obj):
    i = slot.name.rfind(".")
    base = slot.name[0:i]
    if base in bpy.data.materials:
        print("replace "+slot.name+" by "+base+" in "+obj.name)
        slot.material = bpy.data.materials[base]
    
def fixMaterials(object):
    for s in object.material_slots:
        if s.name.rfind(".")>-1:
            replaceMaterial(s,obj)
        
# -----------------------------

print (" --- REPLACE MATERIALS --- ")     

for obj in s.objects:
	fixMaterials(obj)

print (" --- REPLACE MATERIALS: DONE ")