I have for my Blender 2.8 addon 2 keyboard shortcuts that I add to the AddonPreferences:

enter image description here

In the init file I use this code to draw them:

class FC_AddonPreferences(AddonPreferences):
    bl_idname = __name__

    def draw(self, context):
        layout = self.layout

        col = layout.column()
        kc = bpy.context.window_manager.keyconfigs.addon
        for km, kmi in addon_keymaps:
            km = km.active()
            kmi.show_expanded = False
            col.context_pointer_set("keymap", km)
            rna_keymap_ui.draw_kmi([], kc, km, kmi, col, 0)

And here is how I add them

addon_keymaps = []

def register():
   # add keymap entry
   kcfg = bpy.context.window_manager.keyconfigs.addon
   if kcfg:
       km = kcfg.keymaps.new(name='3D View', space_type='VIEW_3D')

       kmi = km.keymap_items.new("object.fc_immediate_mode_op", 'P', 'PRESS', shift=True, ctrl=True)

       kmi_mnu = km.keymap_items.new("wm.call_menu", "Q", "PRESS", shift=True)
       kmi_mnu.properties.name = FC_Main_Menu.bl_idname
       kmi_mnu.active = True

       addon_keymaps.append((km, kmi))
       addon_keymaps.append((km, kmi_mnu))

This works, but when I save the settings and reopen Blender the changes that the user made are gone and reset to default.

What am I missing? Thx!


1 Answer 1


I know this is a fairly late response but I'm going to post my findings anyways in case someone else gets stuck like we did.

From my own testing, the problem comes from this line

km = kcfg.keymaps.new(name='3D View', space_type='VIEW_3D')

For some reason Blender doesn't permanently save keymaps to 3D View. I switched it to 'Object Mode' and now it works fine. Code looks like this now:

km = kcfg.keymaps.new(name='Object Mode', space_type='VIEW_3D')

I'm pretty sure other modes like 'Mesh' work too but I haven't tested it. Sorry its not a full answer. I myself am not sure why this happens but I thought I'd share regardless.

EDIT: Another test with a different script did allow me to save a keymap to 3D View which stayed after restarting Blender. This is quite odd honestly since the code is mostly the same. Maybe its a conflict with another addon? Regardless, if you take anything away from this, it is that you should try different modes to save the keymaps to.

  • $\begingroup$ Hi man, this doesnt work for me, I get an error then in the Preferences dialog. And still saving with name = "3D View" doesnt persist. Issue is still open : developer.blender.org/T60766 $\endgroup$
    – Jayanam
    Jun 6, 2019 at 4:32
  • $\begingroup$ Damn, I guess this is a bug after all :/ Does it still happen if you switch space_type to = 'EMPTY'? Just for testing purposes. Sorry I couldn't help :( $\endgroup$
    – MizuiroNo
    Jun 6, 2019 at 8:23
  • $\begingroup$ Same, not persisted $\endgroup$
    – Jayanam
    Jun 7, 2019 at 11:36

You must log in to answer this question.

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