I can't understand why a basic cube selects fine but extruding the cube causes this to no longer work. It runs into seemingly random extreme indexes.
The error is
"Array iterator out of range: (index: <"random" large number, sometimes negative>)"
which leads me to believe there's something very important I don't understand about selecting faces or materials in the prop collection. Any ideas? This is just a snippet of my code but the bottom line is where the error begins.
import bpy #list objects bpy.ops.object.mode_set(mode='OBJECT') scene = bpy.context.scene objlist = [obj for obj in scene.objects] #selects an object and begins the process for objindex in range(len(objlist)): bpy.context.scene.objects.active = bpy.data.objects[objindex] active_obj = bpy.context.scene.objects.active if active_obj.type == "MESH": #checks we're working with a mesh type object mesh = active_obj.data #BEGIN FIXING FACES AFTER FIXING OBJECT MATERIALS print ("Processing mesh '" + mesh.name + "'") bpy.ops.object.mode_set(mode='EDIT') bpy.context.tool_settings.mesh_select_mode = [False, False, True] #selects face mode face_list = [face for face in mesh.polygons] for face in face_list: #deselects all faces face.select = False for face in range(len(face_list)): #for every face in the mesh do below bpy.ops.object.mode_set(mode='EDIT') face_list[face].select = True #get image from material assigned, assign image to face BELOW mat_data = active_obj.material_slots[face_list[face].material_index].material