Is there any way to find out via Python at which point of the Timeline (at which subframe) fcurve reaches a certain value, without actually changing the current subframe? I have found out that it was possible to get certain keyframe_points coordinates on the timeline, but is there any way to analyze the whole fcurve somehow?

Thanks in advance!


Using FCurve.evaluate(frame) and numpy

In this related answer have found the minimum of an fcurve based on 0.01 subframe increments, instead here will find the first point where the fcurve is greater than a given value.

Test script, loops over all actions and prints the frame (and value) where it first exceeds value.

import bpy
import numpy as np

value = 10

frames = np.arange(1, 250, 0.01)

for action in bpy.data.actions:
    for fc in action.fcurves:
        points = np.vectorize(fc.evaluate)(frames)

        hit = np.where(points > value)[0]
        if hit.size:
            f = hit[0]

            print(f"{frames[f]} : value {points[f]}")
  • 1
    $\begingroup$ Thank you! FCurve.evaluate(frame) is exactly what I was looking for! $\endgroup$ Aug 8 '20 at 19:26

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.