I want to iterate over the faces of a mesh and get the diffuse color of the material that is assigned to the face. How can I get the material that is assigned to the face of the object and the diffuse color of that material?
1 Answer
import bpy
context = bpy.context
obj = context.object
mesh = obj.data
for f in mesh.polygons: # iterate over faces
print("face", f.index, "material_index", f.material_index)
slot = obj.material_slots[f.material_index]
mat = slot.material
if mat is not None:
print(mat.name)
print(mat.diffuse_color)
else:
print("No mat in slot", f.material_index)
bpy.context.object.active_material.diffuse_color
, also try searching on the site, chances are someone had this same issue or something similar, ie: blender.stackexchange.com/questions/27631/…. Combining those should help and give you some pointers. $\endgroup$