How to get vertices coordinates from animated mesh?

Hi all,
I’m new to Blender and Python. I made an animation from Plane mesh using Armature, now i want to export coordinates of all vertices each frame. But it seems nothing change, every vertex show same position as frame 1 (base mesh).
This is code which i used:


import bpy
obj = bpy.data.objects["Plane"]
mesh = bpy.data.meshes["Plane"]
start_frame = 0
end_frame = 40
for f in range(start_frame, end_frame): 
  bpy.context.scene.frame_set(f)
  # Iterate over vertices  
  for v in mesh.vertices:   
    print(obj.matrix_world * v.co)

any help would be highly appreciated :). Thanks

how’s your mesh animated? via shape keys?

no, i use bone to make animation.

mesh = bpy.data.meshes["Plane"]

should be

mesh = obj.data

instead

But still, mesh refers to the actual mesh data, which doesn’t change if animated by armature.

You need to use obj.to_mesh() for every frame to get a mesh with (armature) modifiers applied.

import bpy

scn = bpy.context.scene
obj = bpy.data.objects["Plane"]


start_frame = 0
end_frame = 40

for f in range(start_frame, end_frame): 
  bpy.context.scene.frame_set(f)
  mesh = obj.to_mesh(scn, True, 'PREVIEW') # apply modifiers with preview settings
  mesh.transform(obj.matrix_world) # apply loc/rot/scale
  # Iterate over vertices
  for v in mesh.vertices:
    print(v.co)
  bpy.data.meshes.remove(mesh) # remove 'posed' mesh

it worked. thanks a lot :slight_smile:

Hi all,
Can you please confirm that this method works in blender 2.9 or not?
I have done a cloth simulation and wanted to extract vertices from the last frame I baked. I tried extracting using the above-suggested solution but it always took vertices from the original mesh (i.e. before adding modifiers).
Thank you