5
$\begingroup$

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

$\endgroup$

1 Answer 1

7
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ This is awesome. Thanks! I suppose the None object can be used in a variety of circumstances $\endgroup$
    – SamFall
    Commented Jan 22, 2015 at 15:30

You must log in to answer this question.

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