Catch those keymaps

18.08.2017 @ Various(Blender, Python)

Are you an addon developer? I have something to show you.

You may know Blender has a -b parameter that lets it run without a GUI. This can be used to render on servers, or in batches (like Render+ does).

What you may not know is that when Blender runs GUI-less the addons keyconfigs aren’t available and trying to access the keymaps raises an AttributeError.

Exception in module register(): '/home/januz/.config/blender/2.79/scripts/addons/'
Traceback (most recent call last):
File "/home/januz/code/blender_RC/bin/2.79/scripts/modules/", line 350, in enable
File "/home/januz/.config/blender/2.79/scripts/addons/", line 1009, in register
km ='Object Mode', space_type='EMPTY')
AttributeError: 'NoneType' object has no attribute 'keymaps'

I have about five addons enabled now that spit this error. It’s harmless and doesn’t affect the render at all but it does fill the screen (and logs) very quickly making it harder to find important errors. Or maybe it just triggers my OCD 🙂

So if you are an addon writer, consider putting keymaps in a try block to catch that exception.

    wm = bpy.context.window_manager
    km ='Object Mode', space_type='EMPTY')

except AttributeError as e:
        # Silence is golden
        # Not running in the background, something actually went wrong.
        # Re-raise the exception
        raise e
All the posts you can read

No comments yet

Leave a Reply

Your email address will not be published.