5

I'd like to, in code, remove a material from a material slot without deleting that material slot (because deleting it would remove the connections between that material slot and the vertices). The only code I've found that can remove materials also deletes the material slot: bpy.ops.object.material_slot_remove()

I've also tried to use the property_unset function in the material slot, but it just doesn't seem to do anything. For example: C.object.material_slots[0].property_unset('material')

Setting the material to something else is fairly straightforward, but setting it to NULL seems impossible, even though it's easy to do via the interface.

This is related to, but not solved by:Python - Set material to material slot

SamFall
  • 312
  • 1
  • 9

1 Answers1

7

Its as easy as bpy.context.object.data.materials[0] = None. Check this answer How to assign a new material to an object in the scene from Python? to see why and how it works.

Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218