Addon Update to 2.8 - KeyError: 'bpy_prop_collection[key]: key "Blender" not found'

Hi,

I have an addon that reads some hotkeys. This works fine in 2.79. But throws an error now in Blender 2.8.

Traceback (most recent call last):
  File "\keymaptest.py", line 19, in execute
KeyError: 'bpy_prop_collection[key]: key "Blender" not found'

location: <unknown location>:-1

The trouble part is the second line in this block. keymaps_3DV:

    wm            = bpy.context.window_manager                       # Blender window manager
    keymaps_3DV   = wm.keyconfigs['Blender'].keymaps['3D View']      # 3D View hotkeys
    circle_keymap = keymaps_3DV.keymap_items['view3d.select_circle'] # Circle select keymap object
    main_key      = circle_keymap.type                               # "C" in this case

I couldn’t find any hint in the new API and the change logs about changes regarding my issue. Blender, Blender User and Blender Addon should still be valid, shouldn’t it? Could somebody please point me into the right direction here why it’s not longer found?

Kind regards

Arunderan

The script to test it:

    # This script is a simple example for an operator that gets called by a button.
# The button to execute it is in the Properties sidebar of the 3D view, in the View tab. 
# The output of the operator gets printed to the console.
# You can't read it in the Info editor.

import bpy

# Our Operator
class XX_OT_print_me(bpy.types.Operator):
    """Print me\nPrint Text to Console"""
    bl_idname = "view.print_me"
    bl_label = "Print hotkey"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self, context):
        print("Operator is executing")

        wm            = bpy.context.window_manager                       # Blender window manager
        keymaps_3DV   = wm.keyconfigs['Blender'].keymaps['3D View']      # 3D View hotkeys
        circle_keymap = keymaps_3DV.keymap_items['view3d.select_circle'] # Circle select keymap object
        main_key      = circle_keymap.type                               # "C" in this case

        print(main_key)

        return {'FINISHED'}
    
# Our Panel
class XX_PT_printmepanel(bpy.types.Panel):
    bl_label = "Print hotkey"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "View"
    
    def draw(self, context):
        layout = self.layout
        
        layout.operator(XX_OT_print_me.bl_idname, text="Print")
    
# Registering our classes. The classes tuple.
classes = (
    XX_OT_print_me,
    XX_PT_printmepanel, 
)

# ------------------- Register Unregister
def register():
    from bpy.utils import register_class
    for cls in classes:
    register_class(cls)

def unregister():
    from bpy.utils import unregister_class
    for cls in classes:
    unregister_class(cls)
    
# For scripting only
if __name__ == "__main__":
    register()

AFAIK, there is no wm.keyconfigs[‘Blender’]
You should use: wm.keyconfigs.default - to access user hotkeys.
Or if you want to create new one then use: wm.keyconfigs.addon - here you should create new hotkeys

Thanks JoseConseco, this seems to do the trick :slight_smile:

keymaps_3DV = wm.keyconfigs.default.keymaps[‘3D View’] gives me the hotkey from the default keymap. .user from the User keymaps. And .addon fom the addons keymaps.

What is curious here is that wm.keyconfigs[‘Blender’] does exist. As told, this method already worked in Blender 2.79 and below. The attached script works fine in Blender 2.79. I would still be interested what has changed that this method doesn’t work anymore. But the important part is that the addon is now working again.

Many thanks :slight_smile: