Get vertex data after adding a shape key

Hi,
i still have some problems understanding the basics of shape keys resp. getting mesh data after applying shape keys.

Let’s say i add a cube to a scene.
Next (in object mode) i add a ‘Basic’ shape key to the object and a new shape key ‘a’ whose value i set to 1.
In Edit Mode i grab two vertices of the cube along z axis to value z = 3.
I change back to object mode. When i move the slider of shape key ‘a’, everything is as it should be.

I now want to check the positions of the changed two vertices, but their outputs do not differ, regardless if i’m starting from edit or object mode:

  • in object mode i’m setting the value of shape key ‘a’ to 0.5. I switch back to edit mode to get the new positions of the vertices. Both 3dview and transform panel tell me that (1,0,3) is the position for that shape key value. But in reality they should be (1,0,1.5)
  • in edit mode the vertices seems to be at maximum value (1,0,3) from the beginning. Even if i turn on ‘Apply shape keys in edit mode’, the positions do not seem to change at all in the transfrom panel (just visually in 3dview)

My question is:
How can i get the correct vertex position dependent from a shape key value?
After that i could go a further step to get the updated positions via python…

Thanks in advance

The shape key vertex locations are stored in keyblocks, more precisely in the data[vertex_index].co attribute

ob = bpy.context.object
ob.data.shape_keys.key_blocks[‘Key 1’].data[#].co

But using your code in object mode, it only returns the maximum coordinates of the transformed vertices. As if only the vertex positions at ‘Key 1’ = 0 and ‘Key 1’ = 1 are known, but not those at intermediate shape key values.
That means changing the key value returns always same positions, namely those of key value 1.
Any idea why?

Oh, I misunderstood. For the final vertex location of a shape key mix, you seem to have to use to_mesh() to apply shape keys (and optionally modifiers):


ob = bpy.context.object
scene = bpy.context.scene
me = ob.to_mesh(scene, True, 'PREVIEW')
me.vertices[#].co

# ...

# remember to clean-up, to_mesh() creates a new datablock,
# but doesn't add it to the scene, so it's easy to forget
bpy.data.meshes.remove(me)

Thank you CoDEmanX! That finally works :slight_smile: