I was making a script that grabs the current keymaps and outputs them as a textfile.
I’m aware you can just export a keymap preset from the preferences and I’m also aware that you don’t need every pre-existing keymap just to add some of your own. This is me just having some fun.
CURRENT RESULT AFTER RUNNING SCRIPT (only part of it because it’s longer than I thought):
kmi = km.keymmap_items.new('wm.call_menu', 'N', 'PRESS', ctrl=True)
kmi = km.keymmap_items.new('wm.call_menu', 'O', 'PRESS', ctrl=True, shift=True)
kmi = km.keymmap_items.new('wm.open_mainfile', 'O', 'PRESS', ctrl=True)
kmi = km.keymmap_items.new('wm.save_mainfile', 'S', 'PRESS', ctrl=True)
kmi = km.keymmap_items.new('wm.save_as_mainfile', 'S', 'PRESS', ctrl=True, shift=True)
kmi = km.keymmap_items.new('wm.quit_blender', 'Q', 'PRESS', ctrl=True)
kmi = km.keymmap_items.new('wm.call_menu', 'Q', 'PRESS')
kmi = km.keymmap_items.new('screen.space_type_set_or_cycle', 'F1', 'PRESS', shift=True)
kmi = km.keymmap_items.new('screen.space_type_set_or_cycle', 'F2', 'PRESS', shift=True)
kmi = km.keymmap_items.new('screen.space_type_set_or_cycle', 'F3', 'PRESS', shift=True)
–
It seems to be working so far but I’m missing the attributes/properties from ceratin Keymaps.
QUESTION:
How can modify my script so it also outputs the attributes of the keymaps that have any, along with their respective values, such as 'view3d.select'
which has attributes like 'extend'
which can be set to True
or False
in different keymaps.
Same situation with the keymaps that call menus like 'wm.call_menu_pie'
which has the attribute 'name'
and the name of the pie menu it’s calling.
–
This is my current script:
import bpy
import os
NameForFile=open("C:\\Users\\Alpha\\Desktop\\keymap_converts.txt","w")
wm = bpy.context.window_manager
def searchForKeymaps():
kc = wm.keyconfigs["blender"]
for km in kc.keymaps:
for kmi in km.keymap_items:
print("Found", kmi.name)
anyModifiers = ""
if kmi.ctrl:
anyModifiers += ", ctrl=" + str(kmi.ctrl)
if kmi.alt:
anyModifiers += ", alt=" + str(kmi.alt)
if kmi.shift:
anyModifiers += ", shift=" + str(kmi.shift)
NameForFile.write("kmi = km.keymmap_items.new(" +
"'" + kmi.idname + "', " +
"'" + kmi.type + "', " +
"'" + kmi.value + "'" +
anyModifiers +")\n")
searchForKeymaps()
#Save and close out the file
NameForFile.close()