# Force redraw / update of curve object

I have written a script that syncs the position of a bezier curve handle to an empty via a handler (bpy.app.handlers.scene_update_post):

def curve_handler(scene):

if bpy.data.objects.get('curve_name') is not None:
curveOb = bpy.data.objects.get('curve_name')
if bpy.data.objects.get('empty_name') is not None:
e = bpy.data.objects.get('empty_name')
curveOb.data.splines[0].bezier_points[1].handle_right = e.location


My problem is that the curve does not get updated. When I select the curve, go to edit mode and back, the handler jumps to the position of the empty. But not when I move the empty in object mode.

My current workaround is the following:

bpy.context.scene.objects.unlink(curveOb)


But that is apparently a super ugly hack. Is there a sane way to force redraw of a curve object in Blender?

What you are trying to do is already possible using a hook modifier. Manually you can go into edit mode, select a point and press ⎈ CtrlH->Hook to new object. This is also available to mesh objects which hooks the new object to the selected vertices.

We can create hooks using python. I'm not sure we can do this without the hook_assign operator, so we need to select the specific point and be in edit mode when we assign the point to the hook.

import bpy

obj = bpy.data.objects['BezierCurve']
# select and make it active (for later edit mode)
obj.select = True
bpy.context.scene.objects.active = obj

b_points = obj.data.splines[0].bezier_points
for p in b_points:
p.select_control_point = False
p.select_right_handle = False
p.select_left_handle = False
b_points[0].select_right_handle = True

# create empty to hook to
hook_obj = bpy.data.objects.new('Hook', None)