0

how can I assign colours to a specific face/polygon in the python API? I have found a way of creating materials, but how can I use them through the API on chosen polygons of an object? Does an object have to be fully covered with a material before you can change that of individual parts?

Thank you for your time!

Kirjain
  • 167
  • 1
  • 5
  • 1
    Possible duplicate of http://blender.stackexchange.com/questions/18544/edit-an-objects-material-in-blender-using-python/18581#18581 – Mutant Bob Jan 27 '16 at 14:31

1 Answers1

1

The mesh doesn't have to be fully covered with a material, but it does have to have material slots(at least two) if you want to be able to change individual parts.

import bpy

obj = bpy.data.objects['Cube']
mat = bpy.data.materials['Red']
mat_slots = obj.material_slots
polys = obj.data.polygons

#add a material slot using a material
obj.data.materials.append(mat)

#remove material from material slot
mat_slots[0].material = None

#add the material slot that will be used for individual face
obj.data.materials.append(mat)

#apply material to one face
polys[0].material_index = 1
cmomoney
  • 2,660
  • 12
  • 17