Why does "material_index" return zeros?

by h_h10a   Last Updated October 14, 2019 12:15 PM - source

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!



Related Questions



Assigning material to every second face via python

Updated March 26, 2015 07:27 AM