# Delete face(s) along axis with python

I'm trying to delete, as in This Example, but Faces instead of vertices along a particular axis. So, as an example (see image) this cube's face that I have selected would need to be deleted along the x axis using python. From the above link (following mostly the 3rd answer), I don't understand how they're setting which axis to delete by, or how to do the operation for faces.

My code is is different, because my needs are different than the example. It doesn't throw an error, it just doesn't do anything

    def _debug(vert):
n_selected = len([v for v in vert if v.select])
n_deselect = len([v for v in vert if not v.select])
print('\nlen vertices = {}, {} selected, {} not selected'.format(
len(vert), n_selected, n_deselect))

x_thresh=0.0
vert = bpy.context.object.data.vertices
_debug(vert)
for v in vert:
if v.co[2] < x_thresh:
v.select = True
_debug(vert)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.delete(type='VERT')
bpy.ops.object.mode_set(mode='OBJECT')


bmesh version

If choosing answers from that question would recommend editing the answer of @CoDEmanX

Test script, removes all faces which have all vertices with an x coordinate less than zero.

import bpy
import bmesh

ob = bpy.context.object
assert ob.type == "MESH"
mat = ob.matrix_world
me = ob.data

if me.is_editmode:
bm = bmesh.from_edit_mesh(me)
else:
bm = bmesh.new()
bm.from_mesh(me)

bmesh.ops.delete(
bm,
geom=[f for f in bm.faces if all(
v.co.x < 1e-6 for v in f.verts)
],
context='FACES'
)

if bm.is_wrapped:
bmesh.update_edit_mesh(me)
else:
bm.to_mesh(me)
me.update()


To remove faces with a normal pointing in the -X direction

bmesh.ops.delete(
bm,
geom=[f for f in bm.faces if f.normal.angle((-1, 0, 0)) < 1e-6
],
context='FACES'
)

• Not working on my end. Am I missing some aspect? – Increality Jun 14 at 5:28
• Please inform of the result you get running above on default cube in either object or edit mode. If you are running it on a mesh that has no faces with all vertices x coordinate > 0 then nothing will appear to happen. (Hope this is not the case) Have edited and added a tolerance to remove verts that are tolerance zero but slightly positive which could result in some faces not being removed on the meridian of the default sphere (for example). If this is what you mean by not working, please, in future expand further. If it still doesn't work can add a gif showing it working at my end. – batFINGER Jun 14 at 9:41
• Works. Please describe in detail what exactly does not work @Increality – brockmann Jun 14 at 11:03
• Thank you. Adding the Remove faces with normal pointing in the -X direction got it working. I was only using it on the cube from my image, not a sphere, but this will be good to know. I assumed it was something I was doing on my end. Thank you for the help @batFINGER – Increality Jun 14 at 16:15