Skip to content

Instantly share code, notes, and snippets.

@iCyP
Last active December 11, 2015 18:18
Show Gist options
  • Save iCyP/4640045 to your computer and use it in GitHub Desktop.
Save iCyP/4640045 to your computer and use it in GitHub Desktop.
blenderのショートカットをcsvで、blender.exeと同じディレクトリに、 keymap.csv として書き出すスクリプト 一部環境(オンボードグラフィックス?)ではフリーズします。 特徴: 1.日本語も出力, ex: Mesh,Make Normals Consistent,法線を一様に,mesh.normals_make_consistent,N+ctrl,N,FALSE,TRUE,FALSE 2.call menuは呼ばれるmenuに変換※ ※日本語変換なし ex:Call menu -> en:Special ja:Special
# coding: utf-8
import bpy
import csv
def char_replacer(str):
for words in char_dic:
str = str.replace(words,char_dic[words])
str = str.capitalize()
return str
# **_ARROW will be grabled .
# "+ "'s space is for visibility
char_dic = {'ZERO' : '0' , 'ONE' : '1' , 'TWO' : '2' , 'THREE' : '3' , 'FOUR' : '4',
'FIVE' : '5', 'SIX' :'6' , 'SEVEN' : '7' , 'EIGHT' : '8' , 'NINE' : '9',
'NUMPAD' : 'Num',
'LEFT_BRACKET':'[','RIGHT_BRACKET':']' , 'PERIOD' : '.' , 'COMMA' : ',',
'ACCENT_GRAVE' : '`', 'PLUS' : '+ ', 'MINUS' : '- ',
"UP_ARROW":"↑","RIGHT_ARROW":"→","DOWN_ARROW":"↓","LEFT_ARROW":"←"}
#ignored propeties(options)
stdprops = ['__doc__', '__module__', '__slots__', 'bl_rna','relative', 'rna_type',
'name','mode','__bool__','__class__','__delattr__','__dir__','__eq__',
'__format__','__ge__','__getattribute__','__gt__','__hash__','__init__',
'__le__','__lt__','__ne__','__new__','__reduce__','__reduce_ex__',
'__repr__','__setattr__','__sizeof__','__str__','__subclasshook__']
#prepair for en y ja name
setting_lang = bpy.context.user_preferences.system
setting_lang.use_international_fonts = True
setting_lang.use_translate_interface = True
with open('keymap.csv','w') as file :
csvwriter = csv.writer(file, quoting = csv.QUOTE_ALL, lineterminator = "\n")
labels = ("mode","name","en","ja","shortcut","key","alt","ctrl","shift","options")
csvwriter.writerow(labels)
#
for mode in bpy.context.window_manager.keyconfigs['Blender'].keymaps:
for function in mode.keymap_items:
#get en y ja name
isCallmenu = function.idname=="wm.call_menu"
if isCallmenu:
#TODO bl_label -> name
setting_lang.use_translate_interface = False
try:
en = getattr(bpy.types,function.properties.name).bl_label
except:
en = function.properties.name
setting_lang.use_translate_interface = True
try:
ja = getattr(bpy.types,function.properties.name).bl_label
except:
ja = function.properties.name
else:
setting_lang.use_translate_interface = False
en = function.name
setting_lang.use_translate_interface = True
ja = function.name
#build keys y shortcut
key = char_replacer(function.type)
alt = function.alt
ctrl = function.ctrl
shift = function.shift
shortcut = key
shortcut += "+alt" if alt else ""
shortcut += "+ctrl" if ctrl else ""
shortcut += "+shift" if shift else ""
#build options
#TODO isCallmenu
options_str = []
if function.map_type != 'MOUSE' or function.map_type != 'NDOF':
for opt in dir(function.properties):
if opt not in stdprops:
try:
options_str.append( opt.capitalize() )
#function.properties[opt]-> type(bool)==int...
option = getattr(function.properties,opt)
options_str.append(str(option))
except:
options_str.append(opt).append("")
#build line line
line = [ mode.name, function.idname, en, ja, shortcut, key, str(alt), str(ctrl),str(shift)] + options_str
csvwriter.writerow(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment