This question already has an answer here:

In Blender 2.80, I've deleted a material and have empty material slots on my objects. I want to clean this up.

I have this bit of code:

def clean_mat_slots(self):

    for ob in bpy.data.objects:
       if ob.type != 'MESH':

       bpy.context.view_layer.objects.active = ob

       # Delete all material slots in bounds object
       for i in range(len(ob.material_slots)):
           print("mat slot:", i)
           ob.active_material_index = i - 1

But it does not clean up the slots as I expect. There are no errors reported when I run the code.

Any ideas?


marked as duplicate by Leander, metaphor_set, David Apr 25 at 12:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.