I have been using Blender's Python API to animate an object falling from a height. The Python program will start the animation and then pause the animation at frame 250. However, I would like the Python program to wait until this process has finished before continuing.
The snippet of code is below, where I want the final line of code to wait for the condition to be set in the pause_at_frame handler. One solution I experimented with, was to create a threading event. I would then start a thread calling pause_at_frame and set the threading event when the current frame was 250. The program would then wait for the threading event to be set. I could not manage to get this working without the program hanging. Any suggestions or solutions would be appreciated.
bpy.context.scene.frame_current = 0
bpy.ops.screen.animation_play()
def pause_at_frame(scene):
frame_current = bpy.context.scene.frame_current
if frame_current == 250:
bpy.ops.screen.animation_cancel()
bpy.context.scene.frame_current = 250
# condition here
for i in range(len(bpy.app.handlers.frame_change_pre)):
bpy.app.handlers.frame_change_pre.pop()
bpy.app.handlers.frame_change_pre.append(pause_at_frame)
# Wait here for condition
OTHER SOLUTION:
The other solution to this scenario is to bake the animation first.
bpy.ops.nla.bake(frame_start=1, frame_end=250, bake_types={'OBJECT'}) removing the need for the program above.