2
$\begingroup$

I want to retrieve the name of the currently active keymap. How do I get it? bpy.types.keymap.name errors out. But the attribute 'name' is available in the API:

enter image description here

What I try to figure out is what keymap is currently the active one. The question is whether it's the Blender, Industry Compatible or a Custom User Keymap...? Do you have an idea?

enter image description here

$\endgroup$
4
  • 3
    $\begingroup$ Never going to be the class property. eg bpy.types.Scene.prop Instead will be an instance, eg bpy.context.scene.prop. To clarify are you perhaps after the active keying set name? Note bpy.types.KeyMap.bl_rna.properties['name'].default is the default value assigned to KeyMap.name $\endgroup$
    – batFINGER
    Jun 19 at 13:25
  • 1
    $\begingroup$ As batfinger said, don’t use the class property. That’s like trying to figure out what color you painted the house based on the original blueprint for it. Additionally, are you talking about the interface key map, as in keyboard key map? Or are you talking about keyframes? $\endgroup$
    – TheLabCat
    Jun 19 at 14:56
  • $\begingroup$ Thanks for the ideas friends. I have updated my description to make it more clear. I am not try to retreive the keying set. I try to find out what keymap is currently the active one. Blender or Industry Compatible, or a custom user keymap. $\endgroup$
    – Tiles
    Jun 19 at 15:49
  • 1
    $\begingroup$ Gotchya. Related blender.stackexchange.com/questions/184422/… $\endgroup$
    – batFINGER
    Jun 19 at 16:14
4
$\begingroup$

You can get the name of the active keymap via Preferences. I'd recommend using the python console to figure out the attribute:

>>> C.preferences.keymap.
                         active_keyconfig
                         as_pointer(
                         bl_rna
                         ...

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

>>> C.preferences.keymap.active_keyconfig
'blender_27x'

Based on that knowledge on how to access the attribute it's pretty much straightforward to implement. Following script is an example on how to print the keyconfig to the console:

import bpy

C = bpy.context
print (C.preferences.keymap.active_keyconfig)

# Alternatively
print (bpy.context.preferences.keymap.active_keyconfig)
$\endgroup$
1

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.