3
$\begingroup$

I use a python script to set up some startup preferences like this:

bpy.context.preferences.view.show_tooltips_python = True

However, there is a particular set of preferences I don't know how to access, the ones in the Keymap section where you specify what spacebar does, what mouse click you use to select, etc.

How can I access these settings?

enter image description here

$\endgroup$
3
$\begingroup$

Search the source

With Developer Extras turned on hover over the enum and choose edit source

This will open up (for me) scripts/keyconfigs/blender.py

    # General settings.
    col = layout.column()
    col.row().prop(self, "select_mouse", text="Select with Mouse Button", expand=True)
    col.row().prop(self, "spacebar_action", text="Spacebar Action", expand=True)
    if is_select_left:
        col.row().prop(self, "gizmo_action", text="Activate Gizmo Event", expand=True)

Notice there is a generic property update method load(self, context)

def load():
    from sys import platform
    from bpy import context
    from bl_keymap_utils.io import keyconfig_init_from_data

    prefs = context.preferences
    kc = context.window_manager.keyconfigs.new(IDNAME)
    kc_prefs = kc.preferences

Ok then to the python console

>>> C.preferences.keymap.active_keyconfig
'blender'

>>> C.window_manager.keyconfigs['blender'].preferences['spacebar_action'] = 2

will set to the third option. The item that matches that number is available enum definition of the the Prefs class.

| improve this answer | |
$\endgroup$
  • $\begingroup$ For your other question re choosing keymap bpy.ops.preferences.keyconfig_import(filepath="pathto/keymap.py") $\endgroup$ – batFINGER Jun 28 at 6:05
  • 1
    $\begingroup$ Thanks for both answers, I've used Edit Source before but a lot of what I see is beyond me. I don't think I would of found the answer without your help. Thanks for taking the time. $\endgroup$ – Armored Wolf Jun 28 at 6:06
  • $\begingroup$ NP. Can be a tricky. There could be another way to get there, couldn't find it quickly. (some thing akin to ob.spacebar_action) Suggest look at bl_keymap_utils.io source $\endgroup$ – batFINGER Jun 28 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.