Is it possible to create an object with bmesh without use an existing mesh?

In the example that I found in API documentation is shown as create a bmesh starting from an existing mesh!
I’m wondering if it’s possible to create from scratch a bmesh with the associated object without initialize the bmesh from an existing mesh and how!
Can someone show me an example, please? Thanks

bm =

after that you can push the data into an existing mesh, or not and write data to a file - or some other external purpose.


Thank you for the reply!
Maybe it’s wrong what I have understood about the bmesh, I was thinking that bmesh can completely replace the old way to make meshes, but probably it’s not correct and both mesh and bmesh are necessary!

As reported here with the new release “the mesh data is accessed in object mode and intended for compact storage, for more flexible mesh editing from python see bmesh”.
So mesh data is for acces in Object Mode and bmesh for editing in Edit Mode, is that correct?

The old way to add faces to a mesh now doesn’t work in 2.63 version, the mesh hasn’t the attribute faces, do you know how to do it with the ner release? Thanks in advance!

Maybe I have found the answer

Maybe this simple example about the use of the bmesh API could be usefull to somoeone!

import bpy
import bmesh

# Create mesh 
me ='myMesh') 

# Create object
ob ='myObject', me)   

#ob.location = origin
ob.show_name = True

# Link object to scene

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

# Hot to create vertices
vertex1 = (0.0, 0.0, 3.0) )
vertex2 = (2.0, 0.0, 3.0) )
vertex3 = (2.0, 2.0, 3.0) )
vertex4 = (0.0, 2.0, 3.0) )

# Initialize the index values of this sequence.
# How to create edges (vertex1, vertex2) ) (vertex2, vertex3) ) (vertex3, vertex4) ) (vertex4, vertex1) )

# How to create a face
# it's not necessary to create the edges before, I made it only to show how create 
# edges too (vertex1, vertex2, vertex3, vertex4) )

# Finish up, write the bmesh back to the mesh

little late but thanks for this lol…was trying to figure out the bmesh way of doing this and stumbled across this post. worked like a charm (slight changes due to api changes)

I am glad to know that it helped someone, even after so many years :smiley:

do you know if there’s a way to add verts/faces without having to do them individually?

See my question here for better explanation: