Warning:
Traceback (most recent call last): File "C:\Users\Patrick\AppData\Roaming\Blender Foundation\Blender\2.71\scripts\addons\io_export_shortcuts2html.py", line 141, in execute
raw_data = get_shortcuts()
File "C:\Users\Patrick\AppData\Roaming\Blender Foundation\Blender\2.71\scripts\addons\io_export_shortcuts2html.py", line 82, in get_shortcuts
desc = idtype.bl_rna.properties[prop].enum_items[attr].description
KeyError: 'bpy_prop_collection[key]: key "GLOBAL" not found'
It’s the error line:
desc = idtype.bl_rna.properties[prop].enum_items[attr].description
# ##### BEGIN GPL LICENSE BLOCK ######
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Export Shortcuts to HTML",
"author": "Yardie",
"version": (0, 1),
"blender": (2, 70, 0),
"location": "File menu",
"description": "Get and Write Shortcuts to HTML file",
"warning": "",
"wiki_url": "",
"category": "Import-Export"}
import bpy
import string
from datetime import datetime, date
#------------------- FUNCTIONS------------------------------
def get_shortcuts():
"""Get the data from the user prefs"""
output = {}
"""populate output with keymaps"""
for prefs in bpy.context.window_manager.keyconfigs.user.keymaps:
#loop through each context
context = prefs.name
print (context)
key_info = {}
for prefs_item in prefs.keymap_items:
# enum in ['KEYBOARD', 'TWEAK', 'MOUSE', 'NDOF', 'TEXTINPUT', 'TIMER'], default 'KEYBOARD'
# From this list add which devices you want to get shortcuts on
# ie I don't have a NDOF device so I didn't include it
if prefs_item.map_type in {'KEYBOARD', 'TWEAK', 'MOUSE', 'TEXTINPUT', 'TIMER'} and prefs_item.active:
# loop through each key combo
modifiers = ""
if prefs_item.any:
modifiers = "Any modifier key"
else:
modifier_key = []
if prefs_item.shift: modifier_key.append("Shift")
if prefs_item.oskey: modifier_key.append("OS Key")
if prefs_item.ctrl: modifier_key.append("Ctrl")
if prefs_item.alt: modifier_key.append("Alt")
modifiers = " + ".join(modifier_key)
#sortable key for dict
sort_key = prefs_item.type + " " + modifiers
if modifiers != "":
modifiers += " + "
base_key = string.capwords(prefs_item.type.replace("MOUSE","_MOUSE").replace("TRACKPAD","TRACKPAD_"),"_").replace("_"," ").replace("Ndof","NDOF ")
#base_key = key_map_item.type #string.capwords(key_map_item.type.replace("MOUSE","_MOUSE").replace("TRACKPAD","TRACKPAD_"),"_").replace("_"," ").replace("Ndof","NDOF ")
if hasattr(prefs_item, "properties") and prefs_item.idname:
idname = prefs_item.idname
mod, opname = idname.split(".")
idname_c = "{!s}_OT_{!s}".format(mod.upper(), opname)
idtype = getattr(bpy.types, idname_c)
description = idtype.bl_rna.description
#args = []
for prop in dir(prefs_item.properties):
if prop in idtype.bl_rna.properties and not prop.startswith("_") and prop not in {"bl_rna", "rna_type"}:
attr = getattr(prefs_item.properties, prop)
#args.append("{!s} = {!r}".format(prop, attr))
if idtype.bl_rna.properties[prop].type == "ENUM": # needs to handle attr = "" ie default of enum?
#needs to handle empty description -> print selected enum "With prop as attr
if attr:
desc = idtype.bl_rna.properties[prop].enum_items[attr].description
if desc == "":
desc = "Where {0} equals {1}".format(prop,string.capwords(attr))
description += " " + desc
elif idtype.bl_rna.properties[prop].type == "BOOLEAN":
if attr:
description += " " + (idtype.bl_rna.properties[prop].description)
#elif idtype.bl_rna.properties[prop].type not in {"INT","FLOAT"}:
# print(" {0} ({1}) = {2} ".format(prop,idtype.bl_rna.properties[prop].type,attr))
if description == "":
description = prefs_item.name
#if idtype.bl_rna.properties[prop].type == "INT":
# description += " " + (idtype.bl_rna.properties[prop].description)
#cmd = ">>>>> bpy.ops.{0}({1})".format(prefs_item.idname, ", ".join(args))
key_info[sort_key] = {"base key": base_key , "modifiers": modifiers, "description": description}
#print ("====> In {0} [{1}{2}] Name {3}
{4}".format(context, modifiers, base_key, prefs_item.name,description))
#if description == "":
# print (cmd)
#print (description)
#for key in sorted(key_info):
# out = key_info[key]
# print("{1}{0} {2}".format(out['base key'],out['modifiers'],out['description']))
output[context]=key_info
return output
def format_html(shortcuts):
"""format the data into html with tables"""
output = "<html><head></head><body><h2>Blender Shortcut Keys</h2>
"
output += "As at {:%c}".format(datetime.now())
for context_key in sorted(shortcuts):
output += "<h3 style=\"color: #FF0000;\">{0}</h3>".format(context_key)
output += """<table border=1>
<thead>
<tr>
<th style=\"color: #0000FF;\">Modifier/s</th>
<th style=\"color: #0000FF;\">Keys</th>
<th>Description</th>
</tr></thead>
"""
key_info = shortcuts[context_key]
#Write the rows
for key_info_key in sorted(key_info):
out = key_info[key_info_key]
output += ("<tr><td style=\"color: #0000FF;\"><b>{0}</b></td>
<td style=\"color: #0000FF;\"><b>{1}</b></td>
<td>{2}</td></tr>
".format(out['modifiers'],out['base key'],out['description']))
output += "</table>
"
output += "</body></html>
"
return output
#------------------- OPERATOR CLASSES ------------------------------
class ShortCuts(bpy.types.Operator):
"""Get and Write Shortcuts to HTML file"""
bl_idname = "objects.shortcuts_export"
bl_label = "Write shortcuts to html"
filepath = bpy.props.StringProperty(subtype="FILE_PATH")
filename = bpy.props.StringProperty(name="File name", default="shortcut_keys.html")
def execute(self, context):
raw_data = get_shortcuts()
html_data = format_html(raw_data)
self.filename="shortcut_keys.html"
file = open(self.filepath, 'w')
file.write(html_data)
file.close()
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(ShortCuts.bl_idname, text="Shortcuts to HTML")
ShortCuts_addon_keymaps = []
# Register and add to the file selector
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_export.append(menu_func)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(ShortCuts.bl_idname, 'F1', 'PRESS', ctrl=True, shift=True, alt=True, oskey=True)
ShortCuts_addon_keymaps.append((km, kmi))
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_export.remove(menu_func)
# Keymapping
# handle the keymap
for km, kmi in ShortCuts_addon_keymaps:
km.keymap_items.remove(kmi)
ShortCuts_addon_keymaps.clear()
if __name__ == "__main__":
register()
You must find the error yourself now…but you can see I have made the shortcuts of this add-on.