I try to remove all the faces of different objects that have a certain material assigned to its face. But I can't get the select part to work.
import bpy
import bmesh
scene = bpy.context.scene
mat1 = bpy.data.materials['c1'] #This is the material name that I want
for ob in scene.objects: #For all objects
if ob.type == 'MESH':
for mat in ob.material_slots:
if mat.material == mat1:
bpy.ops.object.editmode_toggle()
mat.material.material_slot_select() # This doesnt work and i dont know if the later code work aswell
me = ob.data
bm = bmesh.from_edit_mesh(me)
faces_select = [f for f in bm.faces if f.select]
bmesh.ops.delete(bm, geom=faces_select, context=5)
bmesh.update_edit_mesh(me, True)
else:
ob.select = False
What is wrong, what shall I write?
Br
Shift G> Material in edit mode.. – gandalf3 Jan 28 '15 at 07:27