Why does "material_index" return zeros? I am new to bpy and I am wondering why the values material_index returns are all zeros.

This is the code I am using:

bpy.ops.object.select_all(action='SELECT')
for obj in bpy.context.selected_objects:
    bpy.context.scene.objects.active = obj
    obj.select = True    
    material_ids = set()
    if obj.data is not None and hasattr(obj.data, "polygons"):
        for polygon in obj.data.polygons:
            material_ids.add(polygon.material_index)


material_ids is a set that only contains 0

Thank you for your help!
The number 'zero' is just a zero based enumerator (eg: 0th,1st,2nd...etc) for the material used on your polygon.
I think, that the enumerator order corresponds to it's position in the (Materials?) editor scroll box.
If you want to see '1'. Create a new material, select your object or a face of it and &quot;Assign&quot; (Button) the object to the second Material in the list. Re-run your script.
..oh, also &quot;set&quot; only contains unique values. So if all your polgons use material '0' there will only be one entry.