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
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 

            print ("Processing mesh '" + mesh.name + "'") 
            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
                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
  • 1
    $\begingroup$ As this is not the complete code, what is the purpose of going to edit mode and setting the faces as active? Also what ensure that the object as material slots defined and associated to a material? $\endgroup$
    – lemon
    Oct 21 '19 at 7:22
  • $\begingroup$ Faces are selected to get the material from that face (as well as assign that image to the UV face), as you can see in the bottom line. Perhaps it is not necessary to do it this way, it does however seem to work fine. I have checks for if an object has a Material or if they don't, and selecting the face will bring up the active material on that face, AND all faces have materials to select from if the object does have one. $\endgroup$
    – InTheBeef
    Oct 21 '19 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.