I have been trying all sorts of things for 3 hours but cannot figure this out. This is the error:
Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender\2.80\scripts\modules\addon_utils.py", line 384, in enable
mod.register()
File "C:\Users\Zyl\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\foo.py", line 53, in register
register_keymaps()
File "C:\Users\Zyl\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\foo.py", line 43, in register_keymaps
kmi.properties.total = 4
AttributeError: 'VIEW_3D_OT_foo' object has no attribute 'total'
Thank you. The error message no longer appears. However, Ctrl+Shift+T still does nothing with the 3D view having focus. See anything else wrong with this?
You’ll have to verify that there are no downstream conflicts since you have your keymap item bound to a very vague keymap. ‘Window’ is about as high level as you can get, as far as keymaps go. There is likely something at a lower level that is consuming your event and preventing your keymap item from being triggered.
Thanks for replying. I tried all other region_type enums (‘HEADER’, ‘CHANNELS’, ‘TEMPORARY’, ‘UI’, ‘TOOLS’, ‘TOOL_PROPS’, ‘PREVIEW’) but still no luck. Isn’t there a single working example I can just copy anywhere? I tried looking into the scripts folder of Blender and searched for keymap with winGrep to find some sort of reference but it’s all quite complicated. I found the following style which I also tried:
sorry, I know it’s confusing because there’s a lot of overloaded terminology, but I was talking about your keymap region name, not your keymap itemregion_type
when you call kc.keymaps.new(name=“Window”) you’re creating a keymap that works in any area that is inherited from Window (which is everything). To make a keymap that works in edit mesh mode, you’ll want to use “Mesh”. If you want one that works in object mode, you’d use “Object Mode”. The region name in keymaps.new is not actually an enum- there are 190(!!) different keymaps in the default keyconfig and they’re not documented anywhere as far as I’m aware. Worst of all, some take priority over others, and this is not documented anywhere either- you’ll have to learn by trial and error unfortunately.
To see all of the potential keymaps, run this script:
import bpy
for i, km in enumerate(bpy.context.window_manager.keyconfigs.default.keymaps):
print(f"{i}\t{km.name}")
Also, as a somewhat related side-note, when you should always check to see if a keymap already exists before calling keymaps.new().
# There's a more 'pythonic' way to do this with one line of code but it's
# not as easily readable for people new to python.
if "Mesh" not in kc.keymaps:
kc.keymaps.new(name="Mesh", etc)
km = kc.keymaps["Mesh"]
Ah I thought that was just some arbitrary name. I set it to 3D View and now it works. Thanks a lot! Maybe we should make a Github repo with user documentation when official docs are such a trainwreck?