I try remove polygon by material_index. Re-assign polygons errors

    new_polys = []

    for polys in me.polygons:
        if polys.material_index == 1:

    me.polygons = new_polys

AttributeError: bpy_struct: attribute "polygons" from "Mesh" is read-only

Any ideas?

  • $\begingroup$ Does it have to be in python? I understand if you need to automate it because you have lots of objects or lots of materials. $\endgroup$
    – Gunslinger
    Aug 5, 2023 at 10:49
  • $\begingroup$ yes of course, I need it in python. I have about 4k objects in my scene, it's impossible to do it manually. $\endgroup$
    – minus_dva
    Aug 5, 2023 at 11:05
  • 1
    $\begingroup$ it's not clear what you are trying to do but based on your first sentence phrase "remove polygons by material_index" it sounds like you want a script that removes all faces that have material index = 1. so i'm not sure why you are trying to assign those faces you want to remove back to the mesh. it's non sensical :D $\endgroup$ Aug 6, 2023 at 9:36

1 Answer 1


To remove all polygons or faces with material_index = 1, Select all objects you want and run the script:

import bpy

material_index = 1


for obj in bpy.context.selected_objects:
    for face in obj.data.polygons:
        face.select = (face.material_index == material_index)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .