1
$\begingroup$

For the life of me I can't figure out why this is happening.

I have an addon I wrote, nothing terribly complicated, just some pie menus and custom operators. I store the kwargs for the keymaps in a dictionary that I loop through on register and use to create the keymap and keymap items.

For some reason the keymaps are not created when run from the __init__ file in my addon.

I can take the create_keymaps function and the keymap_settings dict and run it in the Blender text editor and it creates the keymaps no problem. The error only occurs when I try to create it on script load in the __init__.

I have tried every possible configuration in the __init__.py, putting the keymap setup into it's own function, putting it before/after the register function, putting it in the body of the __init__ file, putting it in the if __name__ == "__main__": section, just every stupid idea in the book.

To me it seems like it might be getting run too early or something, I can't really tell, because other than this the addon works fine, everything loads and runs with no Traceback, so it's hard to tell exactly where it's going wrong.

Here is the code for the __init__.py file in it's entirety.

Thanks for any help.

$\endgroup$

1 Answer 1

1
$\begingroup$

Okay I guess I figured it out, I was accidentally using a new reference to the wm.addon_keyconfig each loop rather than at the start of the register_keymaps function.

def register_keymaps():
    # this line needs to go up here
    wm = bpy.context.window_manager

    for setting in KMS:
        args = list(dict(sorted(setting.items())).values())
        alt, class_name, ctrl, letter, name, region_type, shift, space_type = args

        # I had it right here:
        # wm = bpy.context.window_manager

        kc = wm.keyconfigs.addon
        km = kc.keymaps.new(name=name, space_type=space_type, region_type=region_type)
        kmi = km.keymap_items.new('wm.call_menu_pie', letter, 'PRESS', shift=shift, ctrl=ctrl, alt=alt)
        kmi.properties.name = class_name
        kmi.active = True

        addon_keymaps.append((km, kmi))
$\endgroup$

You must log in to answer this question.

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