I would like to animate an object using vertices as anchors. Blender 2.70a implements the Laplacian deformation method for methods. I have the following code to familiarise myself with hooks. As a trial, I create a for loop to increment the frame number and set the hook location in that frame to a position chosen from a list of coordinates. However, when I scroll back through the frames, the hook location is always in the same place. So the following code is setting the hook location for the entire timeline, not frame-by-frame.

import bpy

# use default cube
ob = bpy.data.objects['Cube']
obdata = bpy.data.meshes['Cube']

# make sure everything is deselected before selecting vertex for hook
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.context.tool_settings.mesh_select_mode = [True, False, False] # (Vertex,Edge,Face)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

# select vertex, add hook, rename to Hook1
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.data.objects['Empty'].name = "Hook1"

# create a list of positions to move the hook through
positions = [(0,0,-2),(0,1,-2),(3,2,-1),(3,4,-1),(1,2,-1)]

scene = bpy.context.scene


for position in positions:
  bpy.data.objects['Hook1'].location = position
  print( bpy.data.objects['Hook1'].location )
  bpy.data.objects['Hook1'].keyframe_insert(data_path="location", frame=frame, index=-1)

UPDATE: Added keyframe insertion.

  • $\begingroup$ You need to insert keyframes for the locations to be remembered, but idk how to do it from python. $\endgroup$
    – gandalf3
    May 18, 2014 at 0:45
  • $\begingroup$ Thanks, I was confused by keyframe_insert but figured it out. Updated script. $\endgroup$
    – noname
    May 18, 2014 at 1:09
  • $\begingroup$ Does it work now? $\endgroup$
    – gandalf3
    May 18, 2014 at 2:37

1 Answer 1


In order for blender to store the location on each frame, you must insert a keyframe.

See the blender API reference for details.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.