Sometimes manage materials with Blender, especially with complex scenes can be tricky if you need to changes materials likes the lookdev phase.
This is why I wanted to share my experience and above all the solution to this problem.
Since the Blender interface does not allow you to reset all Slots Materials, I created a Python script that does exactly this.
Mainly the script acts only on the current selection resetting all the Slots Materials by running the execute command.
Below you will find the script with the appropriate comments.
#CLEAN UP SLOT MATERIAL FOR SELECTED OBJECT --------
selection_names = bpy.context.selected_objects
for obj in selection_names:
bpy.context.view_layer.objects.active = obj
for x in obj.material_slots: #For all of the materials in the selected object:
obj.active_material_index = 0 #select the top material
bpy.ops.object.material_slot_remove() #delete it
I hope it will come in handy!