0
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ You mean selecting faces which have a specific material? $\endgroup$
    – Tak
    Jan 6, 2017 at 21:17

1 Answer 1

3
$\begingroup$
    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()
$\endgroup$
1
  • $\begingroup$ I think it would be helpful to add some description of how the code works. $\endgroup$ Jan 7, 2017 at 12:07

You must log in to answer this question.

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