# Python: Selecting faces from a Material Index

How can you select faces from a material index in edit mode through Python?

• You mean selecting faces which have a specific material? – Tak Jan 6 '17 at 21:17

    import bpy
import bmesh

index = 2  # required index

bpy.ops.object.mode_set(mode = 'EDIT')
ob = bpy.context.object
me  = ob.data
bm = bmesh.from_edit_mesh(me)

for face in bm.faces:
if face.material_index == index:
face.select = True

me.update()

• I think it would be helpful to add some description of how the code works. – Ray Mairlot Jan 7 '17 at 12:07