2
$\begingroup$

I selected multiple keyframes on the Dope Sheet > summary (multiple objects then).

I'd like to deselect one keyframe every two (selected, not-selected, selected, ...), like a true-false in the list of keyframes.

Bonus: I'll also like to deselect every nth frame.

$\endgroup$
1

1 Answer 1

1
$\begingroup$

My point was to DEselect, so here's the working script based on link provided:

bl_info = {
    "name": "Partial Deselect",
    "blender": (3, 0, 0),
    "category": "Object",
}

import bpy

def main(context, nthkey=2):
        for action in bpy.data.actions:
            for channel in action.fcurves:
                for key in channel.keyframe_points.values()[0::nthkey]:
                    key.select_control_point = False
                    key.select_left_handle = False
                    key.select_right_handle = False

class ChannelSelect4Key(bpy.types.Operator):
    """Partial deSelect"""      # Use this as a tooltip for menu items and buttons.
    bl_idname = "anim.channel_select_4th"
    bl_label = "DeSelect 1 keyframe every 4 keys"
    bl_options = {'REGISTER', 'UNDO'}  # Enable undo for the operator.

    def execute(self, context):
        main(context, 4)
        return {'FINISHED'}
                            
class ChannelSelect3Key(bpy.types.Operator):
    """Partial deSelect"""      # Use this as a tooltip for menu items and buttons.
    bl_idname = "anim.channel_select_3th"
    bl_label = "DeSelect 1 keyframe every 3 keys"
    bl_options = {'REGISTER', 'UNDO'}  # Enable undo for the operator.

    def execute(self, context):
        main(context, 3)
        return {'FINISHED'}


class ChannelSelect2Key(bpy.types.Operator):
    '''Select odd keys for selected channels in the dopesheet'''
    bl_idname = "anim.channel_select_2nd"
    bl_label = "DeSelect 1 keyframe every 2 keys (even)"
    bl_options = {'REGISTER', 'UNDO'}  # Enable undo for the operator.

    def execute(self, context):
        main(context, 2)
        return {'FINISHED'}

def menu_func(self, context):
    self.layout.operator(ChannelSelect4Key.bl_idname)
    self.layout.operator(ChannelSelect3Key.bl_idname)
    self.layout.operator(ChannelSelect2Key.bl_idname)

def register():
    bpy.utils.register_class(ChannelSelect4Key)
    bpy.utils.register_class(ChannelSelect3Key)
    bpy.utils.register_class(ChannelSelect2Key)
#    bpy.types.VIEW3D_MT_object.append(menu_func)  # Adds the new operator to an existing menu.

def unregister():
    bpy.utils.unregister_class(ChannelSelect4Key)
    bpy.utils.unregister_class(ChannelSelect3Key)
    bpy.utils.unregister_class(ChannelSelect2Key)

# This allows you to run the script directly from Blender's Text editor
# to test the add-on without having to install it.
if __name__ == "__main__":
    register()

You'll need to enable Edit > Operator Search through Edit > Preferences > Interface > Developers Extra and search for 4 or 3 or 2, and you'll get the deselection.

$\endgroup$

You must log in to answer this question.

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