# 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 ")