1
$\begingroup$

You can call the Change Keying Set menu by hotkey Shift+Ctrl+Alt+I. But you cannot assign a hotkey to one of the single keying sets. It's always the whole menu. So I want to create a button in the tool shelf for the active keying set method LocRotScale to save me some clicks.

I would expect that a inserted button with col.operator("anim.keying_set_active_set", text="LocRotScale").type = 'LocRotScale' would set the keying set to LocRotScale. But it just calls the Change Keying Set menu. And throws me an error too.

TypeError: bpy_struct: item.attr = val: enum "LocRotScale" not found in ('DEFAULT')

How can i insert a button that sets the Keying set to LocRotScale directly with one click?

$\endgroup$

2 Answers 2

4
$\begingroup$

The anim.keying_set_active_set operator invokes a menu that lists the available keying sets. It does have a type property to bypass the menu, which allows you to specify the type value when calling it directly, but it doesn't seem to work when placing the operator in a panel or when setting keyboard shortcuts to use it - it looks like it is most likely due to the acceptable values being a dynamic list.

Changing the keying set is a simple task so it's easy to make a substitute yourself.

class SetKeyingSetOperator(bpy.types.Operator):
    """Set the active keying set"""
    bl_idname = 'anim.set_keyingset'
    bl_label = 'Set the active keying set'

    type = bpy.props.StringProperty(default='LocRotScale')

    def execute(self, context):
        ks = context.scene.keying_sets_all
        ks.active = ks[self.type]
        return {'FINISHED'}

Then you can use this operator to add a button in your panel.

row.operator('anim.set_keyingset', text='LocRot').type = 'LocRot'

This can all be put into an addon which can also setup some keyboard shortcuts to go with it. You can get the addon here, and adjust it to your liking.

As most keys are in use now, I used the key modifier setting. This isn't very popular yet, but it makes a normal key behave like ⎈ Ctrl or ⇧ Shift - in this configuration you hold down K and press Y and it will set the keying set to Location. KU for Rotation and KI for LocRotScale

$\endgroup$
3
  • $\begingroup$ Works great. Many thanks. However, i cannot get it to work with WholeCharacter. I have forced the enum to show with a wrong term. And there is indeed WholeCharacter missing. This is what we have in the enum: ('ACTIVE', 'Location', 'Rotation', 'Scaling', 'BUILTIN_KSI_LocRot', 'BUILTIN_KSI_LocScale', 'LocRotScale', 'BUILTIN_KSI_RotScale', 'BUILTIN_KSI_VisualLoc', 'BUILTIN_KSI_VisualRot', 'BUILTIN_KSI_Vis). A few items are missing. For example Available, and of course WholeCharacter. Any idea how i can get WholeCharacter to work too? $\endgroup$
    – Tiles
    Commented Mar 27, 2016 at 9:10
  • $\begingroup$ The list you show is the bl_idname of each keying set. The addon uses the bl_label which is the user visible name and can include spaces. I have updated the addon to include a comment that shows how to get a list of values. [k.bl_label for k in bpy.context.scene.keying_sets_all] $\endgroup$
    – sambler
    Commented Mar 27, 2016 at 10:41
  • $\begingroup$ For LocRot, I had to set ks.active = ks['Location & Rotation'] in the latest version 2.92.0 $\endgroup$ Commented Aug 26, 2021 at 12:18
1
$\begingroup$

You can modify 'Location' in the following to whatever you need from the Active Keying Set menu. Be sure to type it exactly as it appears in the menu, spaces, commas, case and all:

import bpy
    
for key in bpy.data.scenes["Scene"].keying_sets_all:
  if key.bl_label == 'Location':
    bpy.data.scenes["Scene"].keying_sets.active = key
$\endgroup$

You must log in to answer this question.

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