I have an issue where I can’t find the current location of a cubes’ global vertex location. The cube is moved and key framed through code, but when I try to find the location (of any vertex) at each subsequent frame, it always returns the location of the cubes’ vertex at the start frame. Follow these steps to replicate the error:

Create a cube called Cube.001

import bpy
import random
Scene_Name = bpy.context.scene.name

def Move(Name):
    bpy.context.object.location[0] = bpy.context.object.location[0] + 2  

def MovingVertex(): 
    C = bpy.context
    aObj = C.active_object

    if aObj == None:
        print('No Mesh seleted')
    vts = aObj.data.vertices
    for count in range(0, 8):
        x = [i.index for i in vts if i.select==True][3]
        if x == None:
            print('1 Vertex selected at least')
        wm = aObj.matrix_world.copy()
        aP = wm * vts[x].co


for frame in range(1, 100):
    bpy.data.scenes[Scene_Name].frame_current = (bpy.data.scenes[Scene_Name].frame_current + 1)
    for Count in  range(1, 2):
        Name = "Cube." + str(format(Count, '03'))
        ob = bpy.data.objects[Name]
        cf = bpy.data.scenes[Scene_Name].frame_current
        ob.keyframe_insert(data_path='location', frame=(cf))

Output of frame number and cubes’ vertex location:

<Vector (3168.8081, -1.3707, -2.5711)>
<Vector (3168.8081, -1.3707, -2.5711)>
<Vector (3168.8081, -1.3707, -2.5711)>
<Vector (3168.8081, -1.3707, -2.5711)>
<Vector (3168.8081, -1.3707, -2.5711)>

What am I doing wrong, how can I get the location of the cubes’ vertex at a given frame?


1 Answer 1


Instead of setting scene.frame_current = frame, run scene.frame_set(frame),

The docs mention this since its a common issue.

Updating all objects animation state in a scene can be very heavy with complex scenes, so it was decided not to do this on setting the frame attribute.

  • $\begingroup$ if the animation is not keyframed this still won't work, see the answer to blender.stackexchange.com/questions/28031/… $\endgroup$
    – rfabbri
    Sep 8, 2015 at 7:13
  • $\begingroup$ @rfabbri, its orthogonal, weather you access input loc/scale/rot or final transformation is up to you, and unrelated to frame changing. $\endgroup$
    – ideasman42
    Sep 8, 2015 at 7:35
  • $\begingroup$ (I'm a noob trying to understand this) I meant the animation type; if it were using constraints instead of keyframes, frame_set alone wouldn't work. See the comments by Chebhou to this question blender.stackexchange.com/questions/33377/… $\endgroup$
    – rfabbri
    Sep 8, 2015 at 7:57
  • $\begingroup$ @rfabbri, your confusing 2 unrelated issues. You can get the input trasform, or final output transform. Which you access depends on what you do. But to say "frame_set alone wouldn't work" is incorrect. Since you imply one value is wrong and the other is right. If you need the final transformation, then you better access that, irrespective on the data being animated or not. $\endgroup$
    – ideasman42
    Sep 8, 2015 at 8:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .