3
$\begingroup$

I tried to redefine a shortcut in my addon registration step, but I can't find which one to change. In the user one (bpy.context.window_manager.keyconfigs.user.keymaps['3D View'].keymap_items) there are 3 transform.translate keymaps.

How can my registration code recognise the one in transform modal map and rebind it to a custom key ? How to restore it in the unregister function ?

$\endgroup$
2
  • $\begingroup$ See the api reference $\endgroup$
    – gandalf3
    Commented Nov 12, 2013 at 20:21
  • $\begingroup$ That's exactly what I followed, but there is nothing about modal map there or am I blind ? $\endgroup$
    – matali
    Commented Nov 12, 2013 at 20:55

1 Answer 1

4
$\begingroup$

Are you after one of these, e.g. rotate?

>>> C.window_manager.keyconfigs.user.keymaps['Transform Modal Map'].keymap_items[5].propvalue
'ROTATE'

I'm pretty sure there's only one modal map for all transform operators (and not changable with python).

import bpy
wm = bpy.context.window_manager
keymap = [k for k in wm.keyconfigs.user.keymaps['Transform Modal Map'].keymap_items if k.type == 'G'] #k.propvalue=="TRANSLATE"]
modal_translate = keymap[0] if len(keymap) > 0 else None
print("\n", modal_translate)
for attr in dir(modal_translate):
    if not attr.startswith("_"):
        val = getattr(modal_translate, attr)
        if type(val) in {int, float, str, bool}:
            print("\t", attr, "=", val)

"""
 <bpy_struct, KeyMapItem("")>
         active = True
         alt = False
         any = False
         ctrl = False
         id = 5
         idname =
         is_user_defined = False
         is_user_modified = False
         key_modifier = NONE
         map_type = KEYBOARD
         name =
         oskey = False
         propvalue = TRANSLATE
         shift = False
         show_expanded = False
         type = G
         value = PRESS
"""

But note that you can't provide an operator name in modal maps. Only the predefined modal operations can be set (propvalue).

$\endgroup$
4
  • $\begingroup$ When I change the shortcut for translate in modal mode under the user preferences, one of the 3 above-mentionned transform.translate go away. So I'm sure I could do it with python by rebinding one of them. problem is which one and how to ensure it works by all users (even those with non-default config). $\endgroup$
    – matali
    Commented Nov 13, 2013 at 20:12
  • $\begingroup$ Not sure how to safely restore a user binding, since blender doesn't call unregister() on quit nor are save_pre / save_post app handlers called (although blender saves to quit.blend). Probably safer to just deactivate an existing keymap and search for it on unregister() to activate again. This way, you don't have to store anything. $\endgroup$
    – CodeManX
    Commented Nov 13, 2013 at 21:25
  • $\begingroup$ Entering the code above, i get : >>> modal_translate.type 'WHEELUPMOUSE'. I try to configure G in translate modal mode to cancel blender's translate in my register addon function (to automatically make a GG shortcut) $\endgroup$
    – matali
    Commented Nov 15, 2013 at 7:05
  • $\begingroup$ Updated code to look for 'G' keybinding and print info. Condition can easily be changed. You should probably look for all map_type == KEYBOARD keymap items with propvalue == 'TRANSLATE' and set active=False. Then add your own new keymap item with propvalue='CANCEL'. $\endgroup$
    – CodeManX
    Commented Nov 15, 2013 at 10:11

You must log in to answer this question.

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