0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ You mean selecting faces which have a specific material? $\endgroup$ – Tak Jan 6 '17 at 21:17
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$
  • $\begingroup$ I think it would be helpful to add some description of how the code works. $\endgroup$ – Ray Mairlot Jan 7 '17 at 12:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.