Skip to main content
Commonmark migration
Source Link

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap

# try retrieving the keymap_item for the view3d.move operator
# unfortunately, keymap_items at register() time is always empty
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?

Edit

#Edit II tried a solution using a persistent frame change handler, hooked up to the load_post event. Still, I was unable to access and change the keymap from there, the issue is the same.

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap

# try retrieving the keymap_item for the view3d.move operator
# unfortunately, keymap_items at register() time is always empty
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?

#Edit I tried a solution using a persistent frame change handler, hooked up to the load_post event. Still, I was unable to access and change the keymap from there, the issue is the same.

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap

# try retrieving the keymap_item for the view3d.move operator
# unfortunately, keymap_items at register() time is always empty
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?

Edit

I tried a solution using a persistent frame change handler, hooked up to the load_post event. Still, I was unable to access and change the keymap from there, the issue is the same.

Bumped by Community user
Notice removed Draw attention by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Tweeted twitter.com/StackBlender/status/1009823717390782469
add another detail
Source Link
aliasguru
  • 11.3k
  • 2
  • 37
  • 74

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')     
# try retrieving the keymap_item for the view3d.move operator
# unfortunately, keymap_items at register() time is always empty
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?

#Edit I tried a solution using a persistent frame change handler, hooked up to the load_post event. Still, I was unable to access and change the keymap from there, the issue is the same.

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')    # try retrieving the keymap_item for the view3d.move operator
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap
 
# try retrieving the keymap_item for the view3d.move operator
# unfortunately, keymap_items at register() time is always empty
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?

#Edit I tried a solution using a persistent frame change handler, hooked up to the load_post event. Still, I was unable to access and change the keymap from there, the issue is the same.

Notice added Draw attention by aliasguru
Bounty Started worth 50 reputation by aliasguru
Source Link
aliasguru
  • 11.3k
  • 2
  • 37
  • 74

How can I modify the Default Blender Keymap within my Add-on module registration code?

Consider the following script block:

import bpy
wm = bpy.context.window_manager    # get window manager
_defaultkm = wm.keyconfigs.default.keymaps    # get default keymap
_move = _defaultkm['3D View'].keymap_items.get('view3d.move')    # try retrieving the keymap_item for the view3d.move operator
_move.active = False    # disable that item

It's purpose is to disable a specific shortcut which is shipped with Blender. If you run this in the Text Editor within a Blender session, it works as I wished and disables one of the standard keymap items.

However, my issue is that I'd like to run that code within the register() function of an Add-on. Within that function, _defaultkm will hold a valid Python object, but keymap_items contains no items at all and get() always returns None, causing the last line of the code to fail. It's worth noting that this fails on all different tricks of retrieving keymaps (such as the one mentioned here), it seems as if I can only access my own Add-on keymaps from within the module registration code.

Is there a way to circumvent this?