I have the following arrays (everything inside a structured array data):
Inside i have a struct called material, which has the following information:
face_start: The index of the first face that the material will be assigned
face_count: The amount of faces that material will be assigned to.
So for example: If face_start is 5, and face_count is 3, the code should assigned the faces 5, 6 and 7.
However it does not seem to apply, which i think it's an issue with the API and i can't seem to figure out properly how to assign said materials to the specific faces.
This is how i am attempting to assign said faces:
bpy.context.view_layer.objects.active = obj bpy.ops.object.mode_set(mode='EDIT') #This is to set select mode to faces bpy.context.tool_settings.mesh_select_mode = [False, False, True] for j in range(len(data[i].materials)): #Here i create a material, for example: mat = bpy.data.materials.new(data[i].name + " Material" + str(j)) obj.data.materials.append(mat) #After assigning all the material stuff, i proceed to assign it to the specific faces. obj.active_material_index = j #I assign the recently added material as the active one #I make a for loop where k is the first index (face_start) and goes to face_start + face_count, so it goes from face X to face X+Y for k in range(data[i].material.face_start[j], data[i].material.face_start[j] + data[i].material.face_count[j]): #I tried both of this, individually and at the same time, but none of them seem to work. face_list[k].material_index = j face_list[k].select = True #This should assign the materials to all the faces where select = True, but it doesn't seem to bpy.ops.object.material_slot_assign() #I deselect everything so the selected faces are not there in the next loop bpy.ops.mesh.select_all(action='DESELECT')
With changing things a little bit, i have achieved to either Assign all the faces to the very first material (aka probably nothing has been done), or it assigns all the the very last. But there doesn't seem to be an inbetween.
I'm probably not understanding the API properly, or there's something that i'm missing, but i'm a bit confused as of how to make it work to assign it to specific faces in a loop. What could i do in this scenario?
Thank you for reading!