1
$\begingroup$

I want to play animation as long as a specific condition is true, once the condition is false the animation will be paused and a specific function will run. The problem is that when I run the below code I find blender pausing (hanging) then jumping to frame 70 straight away (as the condition is always false, which is fine) instead of playing frame by frame. Any thoughts how I can run the animation normally frame by frame through python then pausing it when needed?

i = 0
while i < 70:
   if condition == True:
     #go to next frame
     scene.frame_set(scene.frame_current + 1)
   else:
     #pause animation and call my function   
     myfunc()                
   i += 1
$\endgroup$
  • 1
    $\begingroup$ What you are seeing is expected behaviour of your operator above. Consider using a frame_change handler, or a modal timer operator. $\endgroup$ – batFINGER Nov 6 '16 at 4:50
0
$\begingroup$

As suggested by @batFINGER, frame_change handler was used as shown below:

def my_handler(scene):
    retVal = myFunc()
    myFunc2(retVal)

if __name__ == "__main__":
    register()
    bpy.app.handlers.frame_change_post.append(my_handler)
$\endgroup$

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.