Unlink "Material" from current "Material slots" (but not remove) with bpy I made script which swap material &quot;Link with Data to Link with OBJECT&quot; for all material slots of active object, then assgin same material for each material-slots again. (or blender simply remove each material from changed material-slot)
import bpy
my_mat = []

ao = bpy.context.active_object
slots = ao.material_slots

for idx in range(len(slots)):
    my_mat.append(slots[idx].material)
    
for sl in slots:
    sl.link = &quot;OBJECT&quot;
    
for idx in range(len(slots)):
    slots[idx].material = my_mat[idx]

It work, but each material now have 2 user (One link with OBJECT, The other Link with DATA)
So I hope to &quot;Unlink&quot; Mateiral which link with &quot;Data&quot;
It can be done from Properties Editor&gt;Material Property,
change link with to Data again, then Unlink Data-block, on current material-slots (DATA)
then change material-slots link (Object), and assgin the material again, to correctly show current material-slot material.
but I can not find good way to do same with bpy.
Swap material link with DATA or OBJECT , and can assgin material for material-slots, but is there good way to un-link material from un-necessary one?
The DATA materials are stored in ao.data.materials. Try
for i in range(len(ao.data.materials)):
    ao.data.materials[i] = None