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$
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$
  • $\begingroup$ This is awesome. Thanks! I suppose the None object can be used in a variety of circumstances $\endgroup$ – SamFall Jan 22 '15 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.