red = bpy.data.materials['red']
blue = bpy.data.materials['blue']
src = bpy.data.objects['Cube']
# make the material slots per-object
src.material_slots[0].link = 'OBJECT'
src.material_slots[0].material = red
# add a slot
src.data.materials.add(blue)
src.material_slots[1].link = 'OBJECT'
# change 2 of the faces to use the second slot
src.data.polygons[2].material_index=1
src.data.polygons[4].material_index=1
obj = bpy.data.objects["copy"]
obj.material_slots[0].link = 'OBJECT'
obj.material_slots[1].link = 'OBJECT'
obj.material_slots[0].material = blue
obj.material_slots[1].material = red
|
Blender python API quick-start
Syntax highlighting by Pygments.