# How can I delete mesh parts with python?

Suppose I have identified or can identifiy some meshparts I no longer want in my mesh and want to delete them, how would I do it?

I know that bmesh.ops.delete exists, I just don't know how to use it, because the API is a bit lacking for that function. :)

Thanks

## 1 Answer

using the bmesh simple template from the text editor, and a bit of snooping around. You should experiment with the geom and context parameters.

The context is enumerated so (source: bmesh_operator_api.h):

enum {
DEL_VERTS = 1,
DEL_EDGES,
DEL_ONLYFACES,
DEL_EDGESFACES,
DEL_FACES,
DEL_ALL,
DEL_ONLYTAGGED
};


This example assumes we have a mesh object in edit-mode and several faces selected. Running the script will delete edges and faces associated with the selection.

import bpy
import bmesh

# Get the active mesh
obj = bpy.context.edit_object
me = obj.data

# Get a BMesh representation
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)

# Show the updates in the viewport
# and recalculate n-gon tessellation.
bmesh.update_edit_mesh(me, True)

• What are the differences between DEL_ONLYFACES, DEL_EDGESFACES and DEL_FACES? – Peter Hilgers Nov 14 '16 at 16:44
• those are the same options you get if you try to delete geometry using X in the viewport, ONLYFACES keeps edges (and verts), EDGESFACES just keeps verts, ...etc.. – zeffii Nov 14 '16 at 17:42