Operator cheat sheet (from the help menu)

writes all operators (including PyOperators) and their default values into a textblock.
Useful for an overview and checking consistancy.

eg. http://www.pasteall.org/7918/python

added rna functions text.clear() and text.write(str)
This commit is contained in:
Campbell Barton
2009-09-16 06:02:56 +00:00
parent 8df1bb99f9
commit cc100eadc5
8 changed files with 173 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ from bpy.__ops__ import add as op_add
from bpy.__ops__ import remove as op_remove
from bpy.__ops__ import dir as op_dir
from bpy.__ops__ import call as op_call
from bpy.__ops__ import as_string as op_as_string
from bpy.__ops__ import get_rna as op_get_rna
# Keep in sync with WM_types.h
@@ -130,7 +131,10 @@ class bpy_ops_submodule_op(object):
return op_get_rna(self.idname())
def __repr__(self):
def __repr__(self): # useful display, repr(op)
return op_as_string(self.idname())
def __str__(self): # used for print(...)
return "<function bpy.ops.%s.%s at 0x%x'>" % (self.module, self.func, id(self))
import bpy

View File

@@ -188,6 +188,9 @@ class INFO_MT_help(bpy.types.Menu):
layout.itemO("help.blender_eshop")
layout.itemO("help.developer_community")
layout.itemO("help.user_community")
layout.itemS()
layout.itemO("help.operator_cheat_sheet")
bpy.types.register(INFO_HT_header)
bpy.types.register(INFO_MT_file)
@@ -246,10 +249,37 @@ class HELP_OT_user_community(HelpOperator):
__label__ = "User Community"
__URL__ = 'http://www.blender.org/community/user-community/'
class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
__idname__ = "help.operator_cheat_sheet"
__label__ = "Operator Cheet Sheet (new textblock)"
def execute(self, context):
op_strings = []
tot = 0
for op_module_name in dir(bpy.ops):
op_module = getattr(bpy.ops, op_module_name)
for op_submodule_name in dir(op_module):
op = getattr(op_module, op_submodule_name)
text = repr(op)
if text.startswith('bpy.ops.'):
op_strings.append(text)
tot += 1
op_strings.append('')
bpy.ops.text.new() # XXX - assumes new text is always at the end!
textblock = bpy.data.texts[-1]
textblock.write('# %d Operators\n\n' % tot)
textblock.write('\n'.join(op_strings))
textblock.name = "OperatorList.txt"
print("See OperatorList.txt textblock")
return ('FINISHED',)
bpy.ops.add(HELP_OT_manual)
bpy.ops.add(HELP_OT_release_logs)
bpy.ops.add(HELP_OT_blender_website)
bpy.ops.add(HELP_OT_blender_eshop)
bpy.ops.add(HELP_OT_developer_community)
bpy.ops.add(HELP_OT_user_community)
bpy.ops.add(HELP_OT_operator_cheat_sheet)