Skip to main content

Blender Python Bmesh module, added in 2.63, provides an alternative method of manipulating meshes "giving Python access to the functions used by Blender’s own mesh editing tools.". Use this tag for question about using the Bmesh module in Python scripts and add-ons.

The bmesh module is discussed in the BMesh Design Document in the Blender wiki. The manual describes the bmesh module thusly:

This API gives access the Blender’s internal mesh editing API, featuring geometry connectivity data and access to editing operations such as split, separate, collapse and dissolve. The features exposed closely follow the C API, giving Python access to the functions used by Blender’s own mesh editing tools.

bmesh manipulation of meshes tends to be faster than using bpy.ops operations on the mesh because there are fewer screen redraws.

Use this tag for questions about using the bmesh module from python.

The usual workflow is to

  • create a new bmesh,
  • copy the mesh data from an object to it,
  • use bmesh module tools to modify the mesh in bmesh format, an
  • replace the original mesh data with the modified bmesh

as shown in this trivial example from the manual:

# This example assumes we have a mesh object selected

import bpy
import bmesh

# Get the active mesh
me = bpy.context.object.data


# Get a BMesh representation
bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(me)   # fill it in from a Mesh


# Modify the BMesh, can do anything here...
for v in bm.verts:
    v.co.x += 1.0


# Finish up, write the bmesh back to the mesh
bm.to_mesh(me)
bm.free()  # free and prevent further access