I made script which swap material "Link with Data to Link with OBJECT" 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)):
for sl in slots:
    sl.link = "OBJECT"
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 "Unlink" Mateiral which link with "Data"

It can be done from Properties Editor>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?


1 Answer 1


The DATA materials are stored in ao.data.materials. Try

for i in range(len(ao.data.materials)):
    ao.data.materials[i] = None
  • $\begingroup$ Thanks yes I could confirm it only remove materials which link with DATA! Then if I hope to remove(unlink) Materials with OBJECT, how I can change it? $\endgroup$
    – tokikake
    Nov 26, 2020 at 3:49
  • $\begingroup$ Because I hope to enhance this script, Swap material-slots with option. then remove un-necessary link (when it remain). your way actually work when I change material DATA to OBJECT, then I hope to know way when change link OBJECT to DATA, and remove material link for OBJECT.. $\endgroup$
    – tokikake
    Nov 26, 2020 at 4:06
  • $\begingroup$ Thanks your answer actually sove my issue..I did not think I can set None ao.materialslots[0].material = None $\endgroup$
    – tokikake
    Nov 26, 2020 at 4:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .