How to get the updated location of a vertices on different frames?

I am trying to extract animated vertex information. I have a scene set up with a simple triangle that is animated via a shape key. On frame 1 its ine one location and in frame 5 it is else where.

Now I am trying to get the location of these vertices on each of the different frames but so far been unable to see to .co get updated.


import bpy



# frames
fr_start=bpy.data.scenes[0].frame_start
fr_end=bpy.data.scenes[0].frame_end

# total frames
total_fr=(fr_end-fr_start)




print("")
print("")
print("total frames=",total_fr)


mesh=bpy.context.selected_objects[0]          #set frame to first one


for r in range(0,total_fr):
    
    print("working frame = ",r+fr_start)
    bpy.data.scenes[0].frame_set(r+fr_start)
    
    mesh.data.update()    #Though this might do it!
    
    if r==0:
        print("capture 1st",mesh.data.vertices[0].co)

    else:
        print("export delta",mesh.data.vertices[0].co)

Any idea on how I can see the updated location of these verts on each frame?

I think you might need object.to_mesh().
http://www.blender.org/documentation/blender_python_api_2_63_release/bpy.types.Object.html#bpy.types.Object.to_mesh

This returns the mesh with all modifiers applied.

if you used frame_current to set the frame, animations would not change geometry - but as this isn’t the case, Shape Keys appears to be treated like a modifier.

Just tested it out and as Atom said, to_mesh() does the job

me = bpy.context.object.to_mesh(scene=bpy.context.scene, apply_modifiers=True, settings='PREVIEW')
for v in me.vertices:
    v.co