how do I get my changes to the mesh data in python to take effect on the actual blender model/mesh/scene/whatever?

here's a video to illustrate my problem:

bcaptain.net/blender-normals.mpeg

and here's the code I wrote to reverse a quad's vertex order:

Code: Select all

sce = bpy.context.scene #sce = bpy.data.scenes.active

ob = sce.objects.active

mesh = bpy.context.active_object.to_mesh(bpy.context.scene, True, 'PREVIEW')

# ** show current normal

mesh.polygons[0].normal

# ** flip vertices of a quad

tmp=mesh.polygons[0].vertices[0]

mesh.polygons[0].vertices[0]=mesh.polygons[0].vertices[3]

mesh.polygons[0].vertices[3]=tmp

tmp=mesh.polygons[0].vertices[1]

mesh.polygons[0].vertices[1]=mesh.polygons[0].vertices[2]

mesh.polygons[0].vertices[2]=tmp

mesh.update( calc_edges=True )

# ** show new normal

mesh.polygons[0].normal