I'm attempting to navigate to a specific frame in the Movie Clip Editor in order to subsequently detect features on the new frame. However, I'm encountering issues with the execution order of my Python code. Initially, I set the desired frame using bpy.context.scene.frame_current = frame to move to the specified frame. Following that, I utilize bpy.context.area.tag_redraw() to refresh the Movie Clip Editor timeline because, for unknown reasons, the frame does not update properly in that editor. Finally, I employ bpy.ops.clip.detect_features() to identify features on the new frame.
The problem arises when executing this code: the updated frame and the newly added tracking points appear simultaneously. Consequently, the tracking points generated by the bpy.ops.clip.detect_features() function are based on the original frame, which is not the desired outcome.
I even attempted using time.sleep() functions to introduce delays before executing the bpy.ops.clip.detect_features() function. However, this approach yielded the same result as before, where the frame updates at the same time as the detection function is called. It appears that the script is not executing in the correct order.
Here is the simple script:
import math
import time
MiddleFrame = int(NumberOfFrames / 2)
bpy.context.scene.frame_current = MiddleFrame
print("Checkpoint1")
time.sleep(2)
bpy.context.area.tag_redraw()
print("Checkpoint2")
time.sleep(1)
bpy.ops.clip.detect_features()
print("Checkpoint3")
time.sleep(1)
print("Checkpoint4")
Results:
Checkpoint1
Checkpoint2
Checkpoint3
Checkpoint4
Frame updates and trackers appear detected from the original frame.
Here is what I want to happen:
Frame changes to the new frame in the timeline.
Checkpoint1
Frame updates in the Novie Clip Editor.
Checkpoint2
Detects feature on the updated frame.
Checkpoint3
Checkpoint4
What am I doing wrong?