This is how to create a new object and add the vertices in the verts list:
import bpy
import bmesh
verts = [(1, 1, 1), (0, 0, 0)] # 2 verts made with XYZ coords
mesh = bpy.data.meshes.new("mesh") # add a new mesh
obj = bpy.data.objects.new("MyObject", mesh) # add a new object using the mesh
scene = bpy.context.scene
scene.objects.link(obj) # put the object into the scene (link)
scene.objects.active = obj # set as the active object in the scene
obj.select = True # select object
mesh = bpy.context.object.data
bm = bmesh.new()
for v in verts:
bm.verts.new(v) # add a new vert
# make the bmesh the object's mesh
bm.to_mesh(mesh)
bm.free() # always do this when finished
This is how to alter an existing mesh:
import bpy
import bmesh
verts = [(1, 1, 1), (0, 0, 0)] # 2 verts made with XYZ coords
mesh = bpy.context.object.data
bm = bmesh.new()
# convert the current mesh to a bmesh (must be in edit mode)
bpy.ops.object.mode_set(mode='EDIT')
bm.from_mesh(mesh)
bpy.ops.object.mode_set(mode='OBJECT') # return to object mode
for v in verts:
bm.verts.new(v) # add a new vert
# make the bmesh the object's mesh
bm.to_mesh(mesh)
bm.free() # always do this when finished