Hi everyone,
I’m facing an issue with a camera constraint in Blender. When I edit a property in a constraint that I added to a camera, the camera’s position doesn’t change immediately.
I’ve tried the following methods to force an update:
bpy.context.view_layer.update()
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=100)
However, it seems that the camera position only updates after the script finishes executing, and I need to get the new position before that.
Has anyone encountered this issue or have suggestions on how to force an immediate update of the camera’s position after changing a constraint property?
Here the code:
def setup_camera(camera, spline, n_points):
# Store the original location and rotation of the camera
original_location = camera.location.copy()
original_rotation_euler = camera.rotation_euler.copy()
# Create a Follow Path constraint if it doesn't exist
follow_path = camera.constraints.new(type="FOLLOW_PATH")
follow_path.target = spline
# follow_path.use_fixed_location = True
camera.location = [0,0,0]
frame_duration = n_points
points = []
for frame in range(0, n_points):
# Set the evaluation time for the path
t = frame / frame_duration # Normalized time
follow_path.offset_factor = t * 100
points.append(camera.location)
print(f"Frame {frame}: Camera Position: {camera.location}")
# Restore the original camera configuration
camera.location = original_location
camera.rotation_euler = original_rotation_euler
# Clean up: Remove the Follow Path constraint
# camera.constraints.remove(follow_path)
return points
Thanks in advance for your help!