Help needed with bmesh.update_edit_mesh()

Hi,

I’ve trying to get into the Python API. BMesh especially interests me. However I can’t seem to get my head wrapped around the update_edit_mesh() method. I’ve tried writing a piece of code which will take a plane (in EDIT mode) and translate it 10 BU’s along the x-axis (Please excuse the “triviality” of the job to be done - it is merely illustrative…)

Now, I’m calling update_edit_mesh() at the end of each loop iteration. What I expect to see is the mesh updating 10 times - much like 10 frames of animation. However, what I see is only the last frame.

Could you please point out what I am missing? I am not a core programmer, so you might have to be patient with me!

import bpy
import bmesh
import mathutils

plane = bpy.context.object.data # get selected object
bplane = bmesh.from_edit_mesh(plane) # create BMesh in EDIT mode

cv = len(bplane.verts) # get number of vertices

g = 0 # initialise loop counter
while (g < 10):
    for i in range(0, cv): # ...for every vertex...
        bplane.verts[i].co += mathutils.Vector((1, 0, 0)) # add x-translation of 1 BU
            
    g += 1 # increment loop counter
    bmesh.update_edit_mesh(plane, False, False) # update calculations to mesh

I have even tried adding a delay loop within the main loop just to see if its happening too fast - but to no avail. Any assistance would be greatly appreciated. Thanks in advance.

Regards
Anurup

scripts run blocking in blender, viewport is refreshed afterwards. If you wanna see the single steps, code an operator that performs one step and click it 10x.

Thanks coDEmanX! So I gather there is no way to see the individual “frames”…

you could use from_mesh and to_mesh to create a multiple meshes, or maybe use shapekeys if vertex count doesn’t change

Thanks again! Will explore the options that you suggested.