Page MenuHome

Addon's keymaps are not registered at Blender opening if the addon's enable state is saved in user preferences
Closed, InvalidPublicBUG

Description

Blender Version
Broken: 2.80

Short description of error

The code bellow illustrates the issue, it register a new shortcut (here for example the translate operator on numpad asterix key). When the addon is activated for the first time, then the shortcut works correctly. If this activation state is saved in user preferences and then Blender reopenned, the shortcut does not works anymore.

bl_info = {
	'name': 'Test',
	'blender': (2, 80, 0),
	'category': '3D View'
	}

import bpy

def register():
	wm = bpy.context.window_manager
	kc =  wm.keyconfigs.active
	km = kc.keymaps['3D View']
	kmi = km.keymap_items.new(idname='transform.translate', type='NUMPAD_ASTERIX', value='PRESS')


def unregister():
	wm = bpy.context.window_manager
	km = wm.keyconfigs.active.keymaps['3D View']
	kmi = km.keymap_items.remove(km.keymap_items['transform.translate'])

if __name__ == "__main__":
	register()

Event Timeline

I have the same issue, the keymaps are not persisted.

Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Confirmed.Mar 27 2020, 2:36 PM
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".

You need to use wm.keyconfigs.addon for this to work as expected.