[SOLVED] Know if material is assigned?

How I can know if a material is assigned to one object? with cycles and python.
Thanks.

Solved


import bpy, bmesh 

bpy.ops.object.mode_set(mode = 'EDIT')  # Go to edit mode to create bmesh
ob = bpy.context.object                 # Reference to selected object
bm = bmesh.from_edit_mesh(ob.data)      # Create bmesh object from object mesh
bm.verts.ensure_lookup_table()          # <- para que no de error
bm.select_mode = {'FACE'}               # Go to face selection mode

# list names materiales applied:
materiales_aplicados = [] 
for face in bm.faces:
    materiales_aplicados.append(ob.material_slots[face.material_index].name)

ob.data.update()                        # Update the mesh from the bmesh data
bpy.ops.object.mode_set(mode = 'OBJECT') 

for i in range(len(ob.material_slots)):
    mat = ob.material_slots[i].name
    if mat in materiales_aplicados:
        print("The material " + str(mat) + " is applied")
    else:
        print("The material " + str(mat) + " not is applied")