You can subscribe to the depsgraph_update_post
application handler to listen to changes in your mesh.
Here's an example script that prints out which face has been deleted. It is not perfect but you can use it and continue to tinker with it. It is still limited and you have to be in Edit Mode before you run the script. It basically checks if the vertices have changed to know which face has been deleted.
import bpy
import bmesh
print("START =====")
obj = bpy.context.object
mesh = obj.data
bm = bmesh.from_edit_mesh(mesh)
bpy.app.handlers.depsgraph_update_post.clear()
faces_curr = {}
faces_prev = {}
def update_face_vertices(face_sets, face, i):
list = [v.index for v in face.verts]
face_sets[i] = set(list)
def set_new_face_vertices():
faces_curr.clear()
for i, face in enumerate(bm.faces):
update_face_vertices(faces_curr, face, i)
def handle_geometry_changed(scene):
set_new_face_vertices()
bmesh.update_edit_mesh(mesh)
for index in faces_curr:
if faces_curr[index] != faces_prev[index]:
print("face with index deleted:", index)
break
faces_prev.update(faces_curr)
bpy.app.handlers.depsgraph_update_post.append(handle_geometry_changed)
set_new_face_vertices()
faces_prev.update(faces_curr)