I'm very new to Blender scripting, and coding in general, so any help would be appreciated.

Basically I'm trying to create a small addon to help me create smaller actions out of my larger ones by duplicating them and deleting the parts I don't need. I've been able to create a small script to set up markers where I want, but I can't seem to figure out how to select all of the keyframes within those two markers, invert that selection (ctrl + i), then and delete them.


1 Answer 1


I would iterate through all the keyframes and check which frame they're on. That's the first number in the x.co vector. Then check that against start/end variables which you would get from markers (didn't include this code). If the frame is between start/end deselect, if outside of that then select it.

import bpy

obj = bpy.context.object             #active object
action = obj.animation_data.action   #current action

start = 20 #first marker variable
end = 80 #second marker variable

for i in action.fcurves:
    for x in i.keyframe_points:
        if x.co[0] > start and x.co[0] < end: #check greater than/less than marker frames
            x.select_control_point=False #deselect if in between markers
            x.select_control_point=True #select if outside of markers
  • $\begingroup$ Hey thanks for responding. I was actually able to get it to work by calling ops.action.select_column(mode='MARKERS_BETWEEN'). The problem I'm having now is getting the script to only work on the active object instead of everything. I'll try your code to see if it solves the problem. $\endgroup$
    – sprokus
    Dec 19, 2019 at 21:23
  • $\begingroup$ Yep, your code worked perfectly. Thanks! $\endgroup$
    – sprokus
    Dec 19, 2019 at 22:46
  • $\begingroup$ Perhaps you could elaborate by explaining how you got this code to work using the operation ops.action.select_column(mode='KEYS'). It's telling me that the context is wrong. $\endgroup$ Aug 4, 2021 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .