I need to be able to tell if a bone property has a keyframe on the current frame. I.e. the property box is yellow and not green.
I know you can evaluate an fcurve but how do you tell if it's a keyframe? Is there an easy way to do this?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
There is no easy way, but you could extend the Object type by a method:
import bpy def is_keyframe(ob, frame, data_path, array_index=-1): if ob is not None and ob.animation_data is not None and ob.animation_data.action is not None: for fcu in ob.animation_data.action.fcurves: if fcu.data_path == data_path: if array_index == -1 or fcu.array_index == array_index: return frame in (p.co.x for p in fcu.keyframe_points) return False bpy.types.Object.is_keyframe = is_keyframe # TEST ob = bpy.context.object pbone = bpy.context.active_pose_bone # True or False ob.is_keyframe(20, pbone.path_from_id("location"), array_index=2)
frame can be int or float,
20 will match a
20.0, but not a subframe like
20.1. If you want to check for full frames, use
round(p.co.x) in the
Talked to ideasman_42, and he may check on adding a native method to retrieve F-Curve and Keyframe objects more easily.