To add a new slot to the material slots for an object:
- We can use the operator object.material_slot_add
Calling this operator creates a new material slot for all selected objects:
1 2 3 |
import bpy bpy.ops.object.material_slot_add() |
But this operator, like all of operators, is context sensitive an may be inconvenience when using.
- We can also append a new material slot to an object directly to its “data.materials” collection.
Execute the following:
1 2 3 |
import bpy bpy.context.object.data.materials.append(None) |
to add a new empty material slot to the active object.
If we need to create a slot and immediately assign a material to it, we can pass the required material in the parameter:
1 2 3 |
import bpy bpy.context.object.data.materials.append(bpy.data.materials['Material.001']) |