Skip to main content
Blender 3.2+ updates
Source Link
p2or
  • 16.1k
  • 10
  • 87
  • 146

You can set the index of the list to 0, iterate through all slots and override the context of material_slot_remove():.

Blender 3.2+

import bpy
from bpy import context

for obj in context.selected_editable_objects:
    obj.active_material_index = 0
    for i in range(len(obj.material_slots)):
        with context.temp_override(object=obj):
            bpy.ops.object.material_slot_remove()

Blender 2.8+

import bpy

for obj in bpy.context.selected_editable_objects:
    obj.active_material_index = 0
    for i in range(len(obj.material_slots)):
        bpy.ops.object.material_slot_remove({'object': obj})

You can set the index of the list to 0, iterate through all slots and override the context of material_slot_remove():

for obj in bpy.context.selected_editable_objects:
    obj.active_material_index = 0
    for i in range(len(obj.material_slots)):
        bpy.ops.object.material_slot_remove({'object': obj})

You can set the index of the list to 0, iterate through all slots and override the context of material_slot_remove().

Blender 3.2+

import bpy
from bpy import context

for obj in context.selected_editable_objects:
    obj.active_material_index = 0
    for i in range(len(obj.material_slots)):
        with context.temp_override(object=obj):
            bpy.ops.object.material_slot_remove()

Blender 2.8+

import bpy

for obj in bpy.context.selected_editable_objects:
    obj.active_material_index = 0
    for i in range(len(obj.material_slots)):
        bpy.ops.object.material_slot_remove({'object': obj})
Source Link
brockmann
  • 12.8k
  • 4
  • 51
  • 94

You can set the index of the list to 0, iterate through all slots and override the context of material_slot_remove():

for obj in bpy.context.selected_editable_objects:
    obj.active_material_index = 0
    for i in range(len(obj.material_slots)):
        bpy.ops.object.material_slot_remove({'object': obj})