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')
return
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')
return
wm = aObj.matrix_world.copy()
aP = wm * vts[x].co
print(bpy.context.scene.frame_current)
print(aP)
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]
bpy.context.scene.objects.active=ob
Move(Name)
MovingVertex()
cf = bpy.data.scenes[Scene_Name].frame_current
ob.keyframe_insert(data_path='location', frame=(cf))
Output of frame number and cubes’ vertex location:
1682
<Vector (3168.8081, -1.3707, -2.5711)>
1683
<Vector (3168.8081, -1.3707, -2.5711)>
1684
<Vector (3168.8081, -1.3707, -2.5711)>
1685
<Vector (3168.8081, -1.3707, -2.5711)>
1686
<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?