| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | # ##### 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 ##### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # <pep8 compliant> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # semi-useful script, runs all operators in a number of different | 
					
						
							|  |  |  | # contexts, cheap way to find misc small bugs but is in no way a complete test. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # only error checked for here is a segfault. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import bpy | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | USE_ATTRSET = False | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  | USE_FILES = ""  # "/mango/" | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | USE_RANDOM = False | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  | USE_RANDOM_SCREEN = False | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | RANDOM_SEED = [1]  # so we can redo crashes | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  | RANDOM_RESET = 0.1  # 10% chance of resetting on each new operator | 
					
						
							|  |  |  | RANDOM_MULTIPLY = 10 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | op_blacklist = ( | 
					
						
							|  |  |  |     "script.reload", | 
					
						
							|  |  |  |     "export*.*", | 
					
						
							|  |  |  |     "import*.*", | 
					
						
							|  |  |  |     "*.save_*", | 
					
						
							|  |  |  |     "*.read_*", | 
					
						
							|  |  |  |     "*.open_*", | 
					
						
							|  |  |  |     "*.link_append", | 
					
						
							|  |  |  |     "render.render", | 
					
						
							| 
									
										
										
										
											2012-11-30 16:15:49 +00:00
										 |  |  |     "render.play_rendered_anim", | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     "sound.bake_animation",    # OK but slow | 
					
						
							|  |  |  |     "sound.mixdown",           # OK but slow | 
					
						
							|  |  |  |     "object.bake_image",       # OK but slow | 
					
						
							|  |  |  |     "object.paths_calculate",  # OK but slow | 
					
						
							|  |  |  |     "object.paths_update",     # OK but slow | 
					
						
							|  |  |  |     "ptcache.bake_all",        # OK but slow | 
					
						
							|  |  |  |     "nla.bake",                # OK but slow | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     "*.*_export", | 
					
						
							|  |  |  |     "*.*_import", | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |     "ed.undo", | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     "ed.undo_push", | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |     "script.autoexec_warn_clear", | 
					
						
							|  |  |  |     "screen.delete",           # already used for random screens | 
					
						
							| 
									
										
										
										
											2012-02-02 05:11:42 +00:00
										 |  |  |     "wm.blenderplayer_start", | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |     "wm.recover_auto_save", | 
					
						
							|  |  |  |     "wm.quit_blender", | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     "wm.url_open", | 
					
						
							|  |  |  |     "wm.doc_view", | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     "wm.doc_edit", | 
					
						
							|  |  |  |     "wm.doc_view_manual", | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     "wm.path_open", | 
					
						
							| 
									
										
										
										
											2014-09-10 23:01:22 +10:00
										 |  |  |     "wm.copy_prev_settings", | 
					
						
							| 
									
										
										
										
											2012-11-30 16:15:49 +00:00
										 |  |  |     "wm.theme_install", | 
					
						
							|  |  |  |     "wm.context_*", | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     "wm.properties_add", | 
					
						
							|  |  |  |     "wm.properties_remove", | 
					
						
							|  |  |  |     "wm.properties_edit", | 
					
						
							|  |  |  |     "wm.properties_context_change", | 
					
						
							| 
									
										
										
										
											2012-11-30 16:15:49 +00:00
										 |  |  |     "wm.operator_cheat_sheet", | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     "wm.interface_theme_*", | 
					
						
							|  |  |  |     "wm.appconfig_*",           # just annoying - but harmless | 
					
						
							|  |  |  |     "wm.keyitem_add",           # just annoying - but harmless | 
					
						
							|  |  |  |     "wm.keyconfig_activate",    # just annoying - but harmless | 
					
						
							|  |  |  |     "wm.keyconfig_preset_add",  # just annoying - but harmless | 
					
						
							|  |  |  |     "wm.keyconfig_test",        # just annoying - but harmless | 
					
						
							|  |  |  |     "wm.memory_statistics",     # another annoying one | 
					
						
							|  |  |  |     "wm.dependency_relations",  # another annoying one | 
					
						
							|  |  |  |     "wm.keymap_restore",        # another annoying one | 
					
						
							|  |  |  |     "wm.addon_*",               # harmless, but dont change state | 
					
						
							|  |  |  |     "console.*",                # just annoying - but harmless | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  | def blend_list(mainpath): | 
					
						
							|  |  |  |     import os | 
					
						
							|  |  |  |     from os.path import join, splitext | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def file_list(path, filename_check=None): | 
					
						
							|  |  |  |         for dirpath, dirnames, filenames in os.walk(path): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # skip '.svn' | 
					
						
							|  |  |  |             if dirpath.startswith("."): | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for filename in filenames: | 
					
						
							|  |  |  |                 filepath = join(dirpath, filename) | 
					
						
							|  |  |  |                 if filename_check is None or filename_check(filepath): | 
					
						
							|  |  |  |                     yield filepath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def is_blend(filename): | 
					
						
							|  |  |  |         ext = splitext(filename)[1] | 
					
						
							| 
									
										
										
										
											2014-04-15 13:11:48 +10:00
										 |  |  |         return (ext in {".blend", }) | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return list(sorted(file_list(mainpath, is_blend))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if USE_FILES: | 
					
						
							|  |  |  |     USE_FILES_LS = blend_list(USE_FILES) | 
					
						
							|  |  |  |     # print(USE_FILES_LS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | def filter_op_list(operators): | 
					
						
							|  |  |  |     from fnmatch import fnmatchcase | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def is_op_ok(op): | 
					
						
							|  |  |  |         for op_match in op_blacklist: | 
					
						
							|  |  |  |             if fnmatchcase(op, op_match): | 
					
						
							|  |  |  |                 print("    skipping: %s (%s)" % (op, op_match)) | 
					
						
							|  |  |  |                 return False | 
					
						
							|  |  |  |         return True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     operators[:] = [op for op in operators if is_op_ok(op[0])] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | def reset_blend(): | 
					
						
							|  |  |  |     bpy.ops.wm.read_factory_settings() | 
					
						
							|  |  |  |     for scene in bpy.data.scenes: | 
					
						
							|  |  |  |         # reduce range so any bake action doesnt take too long | 
					
						
							|  |  |  |         scene.frame_start = 1 | 
					
						
							|  |  |  |         scene.frame_end = 5 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |     if USE_RANDOM_SCREEN: | 
					
						
							|  |  |  |         import random | 
					
						
							|  |  |  |         for i in range(random.randint(0, len(bpy.data.screens))): | 
					
						
							|  |  |  |             bpy.ops.screen.delete() | 
					
						
							|  |  |  |         print("Scree IS", bpy.context.screen) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def reset_file(): | 
					
						
							|  |  |  |     import random | 
					
						
							|  |  |  |     f = USE_FILES_LS[random.randint(0, len(USE_FILES_LS) - 1)] | 
					
						
							|  |  |  |     bpy.ops.wm.open_mainfile(filepath=f) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if USE_ATTRSET: | 
					
						
							|  |  |  |     def build_property_typemap(skip_classes): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         property_typemap = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for attr in dir(bpy.types): | 
					
						
							|  |  |  |             cls = getattr(bpy.types, attr) | 
					
						
							|  |  |  |             if issubclass(cls, skip_classes): | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ## to support skip-save we cant get all props | 
					
						
							|  |  |  |             # properties = cls.bl_rna.properties.keys() | 
					
						
							|  |  |  |             properties = [] | 
					
						
							|  |  |  |             for prop_id, prop in cls.bl_rna.properties.items(): | 
					
						
							|  |  |  |                 if not prop.is_skip_save: | 
					
						
							|  |  |  |                     properties.append(prop_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             properties.remove("rna_type") | 
					
						
							|  |  |  |             property_typemap[attr] = properties | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return property_typemap | 
					
						
							|  |  |  |     CLS_BLACKLIST = ( | 
					
						
							|  |  |  |         bpy.types.BrushTextureSlot, | 
					
						
							|  |  |  |         bpy.types.Brush, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     property_typemap = build_property_typemap(CLS_BLACKLIST) | 
					
						
							|  |  |  |     bpy_struct_type = bpy.types.Struct.__base__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def id_walk(value, parent): | 
					
						
							|  |  |  |         value_type = type(value) | 
					
						
							|  |  |  |         value_type_name = value_type.__name__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         value_id = getattr(value, "id_data", Ellipsis) | 
					
						
							|  |  |  |         value_props = property_typemap.get(value_type_name, ()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for prop in value_props: | 
					
						
							|  |  |  |             subvalue = getattr(value, prop) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if subvalue == parent: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2013-03-17 10:26:23 +00:00
										 |  |  |             # grr, recursive! | 
					
						
							|  |  |  |             if prop == "point_caches": | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |             subvalue_type = type(subvalue) | 
					
						
							|  |  |  |             yield value, prop, subvalue_type | 
					
						
							|  |  |  |             subvalue_id = getattr(subvalue, "id_data", Ellipsis) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if value_id == subvalue_id: | 
					
						
							|  |  |  |                 if subvalue_type == float: | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |                 elif subvalue_type == int: | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |                 elif subvalue_type == bool: | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |                 elif subvalue_type == str: | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |                 elif hasattr(subvalue, "__len__"): | 
					
						
							|  |  |  |                     for sub_item in subvalue[:]: | 
					
						
							|  |  |  |                         if isinstance(sub_item, bpy_struct_type): | 
					
						
							|  |  |  |                             subitem_id = getattr(sub_item, "id_data", Ellipsis) | 
					
						
							|  |  |  |                             if subitem_id == subvalue_id: | 
					
						
							|  |  |  |                                 yield from id_walk(sub_item, value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if subvalue_type.__name__ in property_typemap: | 
					
						
							|  |  |  |                     yield from id_walk(subvalue, value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # main function | 
					
						
							|  |  |  |     _random_values = ( | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |         None, object, type, | 
					
						
							|  |  |  |         1, 0.1, -1,  # float("nan"), | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |         "", "test", b"", b"test", | 
					
						
							|  |  |  |         (), [], {}, | 
					
						
							|  |  |  |         (10,), (10, 20), (0, 0, 0), | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |         {0: "", 1: "hello", 2: "test"}, {"": 0, "hello": 1, "test": 2}, | 
					
						
							|  |  |  |         set(), {"", "test", "."}, {None, ..., type}, | 
					
						
							|  |  |  |         range(10), (" " * i for i in range(10)), | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def attrset_data(): | 
					
						
							|  |  |  |         for attr in dir(bpy.data): | 
					
						
							|  |  |  |             if attr == "window_managers": | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             seq = getattr(bpy.data, attr) | 
					
						
							|  |  |  |             if seq.__class__.__name__ == 'bpy_prop_collection': | 
					
						
							|  |  |  |                 for id_data in seq: | 
					
						
							|  |  |  |                     for val, prop, tp in id_walk(id_data, bpy.data): | 
					
						
							|  |  |  |                         # print(id_data) | 
					
						
							|  |  |  |                         for val_rnd in _random_values: | 
					
						
							|  |  |  |                             try: | 
					
						
							|  |  |  |                                 setattr(val, prop, val_rnd) | 
					
						
							|  |  |  |                             except: | 
					
						
							|  |  |  |                                 pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | def run_ops(operators, setup_func=None, reset=True): | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     print("\ncontext:", setup_func.__name__) | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     # first invoke | 
					
						
							|  |  |  |     for op_id, op in operators: | 
					
						
							|  |  |  |         if op.poll(): | 
					
						
							|  |  |  |             print("    operator:", op_id) | 
					
						
							| 
									
										
										
										
											2012-03-09 00:41:09 +00:00
										 |  |  |             sys.stdout.flush()  # in case of crash | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             # disable will get blender in a bad state and crash easy! | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  |             if reset: | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |                 reset_test = True | 
					
						
							|  |  |  |                 if USE_RANDOM: | 
					
						
							|  |  |  |                     import random | 
					
						
							|  |  |  |                     if random.random() < (1.0 - RANDOM_RESET): | 
					
						
							|  |  |  |                         reset_test = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if reset_test: | 
					
						
							|  |  |  |                     if USE_FILES: | 
					
						
							|  |  |  |                         reset_file() | 
					
						
							|  |  |  |                     else: | 
					
						
							|  |  |  |                         reset_blend() | 
					
						
							|  |  |  |                 del reset_test | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |             if USE_RANDOM: | 
					
						
							|  |  |  |                 # we can't be sure it will work | 
					
						
							|  |  |  |                 try: | 
					
						
							|  |  |  |                     setup_func() | 
					
						
							|  |  |  |                 except: | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 setup_func() | 
					
						
							| 
									
										
										
										
											2011-03-22 14:37:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 05:21:37 +00:00
										 |  |  |             for mode in {'EXEC_DEFAULT', 'INVOKE_DEFAULT'}: | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |                 try: | 
					
						
							|  |  |  |                     op(mode) | 
					
						
							|  |  |  |                 except: | 
					
						
							|  |  |  |                     #import traceback | 
					
						
							|  |  |  |                     #traceback.print_exc() | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |                 if USE_ATTRSET: | 
					
						
							|  |  |  |                     attrset_data() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  |     if not operators: | 
					
						
							|  |  |  |         # run test | 
					
						
							|  |  |  |         if reset: | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |             reset_blend() | 
					
						
							|  |  |  |         if USE_RANDOM: | 
					
						
							|  |  |  |             # we can't be sure it will work | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 setup_func() | 
					
						
							|  |  |  |             except: | 
					
						
							|  |  |  |                 pass | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             setup_func() | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-26 21:19:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | # contexts | 
					
						
							|  |  |  | def ctx_clear_scene():  # copied from batch_import.py | 
					
						
							|  |  |  |     unique_obs = set() | 
					
						
							|  |  |  |     for scene in bpy.data.scenes: | 
					
						
							|  |  |  |         for obj in scene.objects[:]: | 
					
						
							|  |  |  |             scene.objects.unlink(obj) | 
					
						
							|  |  |  |             unique_obs.add(obj) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # remove obdata, for now only worry about the startup scene | 
					
						
							|  |  |  |     for bpy_data_iter in (bpy.data.objects, bpy.data.meshes, bpy.data.lamps, bpy.data.cameras): | 
					
						
							|  |  |  |         for id_data in bpy_data_iter: | 
					
						
							|  |  |  |             bpy_data_iter.remove(id_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_mesh(): | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_mesh_extra(): | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     bpy.ops.object.vertex_group_add() | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  |     bpy.ops.object.shape_key_add(from_mix=False) | 
					
						
							|  |  |  |     bpy.ops.object.shape_key_add(from_mix=True) | 
					
						
							|  |  |  |     bpy.ops.mesh.uv_texture_add() | 
					
						
							|  |  |  |     bpy.ops.mesh.vertex_color_add() | 
					
						
							|  |  |  |     bpy.ops.object.material_slot_add() | 
					
						
							|  |  |  |     # editmode last! | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_mesh_empty(): | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  |     bpy.ops.mesh.select_all(action='SELECT') | 
					
						
							|  |  |  |     bpy.ops.mesh.delete() | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_curves(): | 
					
						
							|  |  |  |     bpy.ops.curve.primitive_nurbs_circle_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | def ctx_editmode_curves_empty(): | 
					
						
							|  |  |  |     bpy.ops.curve.primitive_nurbs_circle_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							| 
									
										
										
										
											2013-09-15 01:46:25 +00:00
										 |  |  |     bpy.ops.curve.select_all(action='SELECT') | 
					
						
							|  |  |  |     bpy.ops.curve.delete(type='VERT') | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | def ctx_editmode_surface(): | 
					
						
							|  |  |  |     bpy.ops.surface.primitive_nurbs_surface_torus_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_mball(): | 
					
						
							|  |  |  |     bpy.ops.object.metaball_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_text(): | 
					
						
							|  |  |  |     bpy.ops.object.text_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_editmode_armature(): | 
					
						
							|  |  |  |     bpy.ops.object.armature_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | def ctx_editmode_armature_empty(): | 
					
						
							|  |  |  |     bpy.ops.object.armature_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  |     bpy.ops.armature.select_all(action='SELECT') | 
					
						
							|  |  |  |     bpy.ops.armature.delete() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | def ctx_editmode_lattice(): | 
					
						
							|  |  |  |     bpy.ops.object.add(type='LATTICE') | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='EDIT') | 
					
						
							|  |  |  |     # bpy.ops.object.vertex_group_add() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_object_empty(): | 
					
						
							|  |  |  |     bpy.ops.object.add(type='EMPTY') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | def ctx_object_pose(): | 
					
						
							|  |  |  |     bpy.ops.object.armature_add() | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='POSE') | 
					
						
							|  |  |  |     bpy.ops.pose.select_all(action='SELECT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_object_paint_weight(): | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     bpy.ops.object.mode_set(mode='WEIGHT_PAINT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  | def ctx_object_paint_vertex(): | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='VERTEX_PAINT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_object_paint_sculpt(): | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='SCULPT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def ctx_object_paint_texture(): | 
					
						
							|  |  |  |     bpy.ops.object.mode_set(mode='TEXTURE_PAINT') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 04:59:30 +00:00
										 |  |  | def bpy_check_type_duplicates(): | 
					
						
							|  |  |  |     # non essential sanity check | 
					
						
							|  |  |  |     bl_types = dir(bpy.types) | 
					
						
							|  |  |  |     bl_types_unique = set(bl_types) | 
					
						
							| 
									
										
										
										
											2012-02-04 11:10:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 04:59:30 +00:00
										 |  |  |     if len(bl_types) != len(bl_types_unique): | 
					
						
							|  |  |  |         print("Error, found duplicates in 'bpy.types'") | 
					
						
							|  |  |  |         for t in sorted(bl_types_unique): | 
					
						
							|  |  |  |             tot = bl_types.count(t) | 
					
						
							|  |  |  |             if tot > 1: | 
					
						
							|  |  |  |                 print("    '%s', %d" % (t, tot)) | 
					
						
							|  |  |  |         import sys | 
					
						
							|  |  |  |         sys.exit(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2012-02-02 04:59:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bpy_check_type_duplicates() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     # reset_blend() | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     import bpy | 
					
						
							|  |  |  |     operators = [] | 
					
						
							|  |  |  |     for mod_name in dir(bpy.ops): | 
					
						
							|  |  |  |         mod = getattr(bpy.ops, mod_name) | 
					
						
							|  |  |  |         for submod_name in dir(mod): | 
					
						
							|  |  |  |             op = getattr(mod, submod_name) | 
					
						
							|  |  |  |             operators.append(("%s.%s" % (mod_name, submod_name), op)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     operators.sort(key=lambda op: op[0]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     filter_op_list(operators) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # for testing, mix the list up. | 
					
						
							|  |  |  |     #operators.reverse() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     if USE_RANDOM: | 
					
						
							|  |  |  |         import random | 
					
						
							|  |  |  |         random.seed(RANDOM_SEED[0]) | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |         operators = operators * RANDOM_MULTIPLY | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |         random.shuffle(operators) | 
					
						
							| 
									
										
										
										
											2012-09-26 21:19:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  |     # 2 passes, first just run setup_func to make sure they are ok | 
					
						
							|  |  |  |     for operators_test in ((), operators): | 
					
						
							|  |  |  |         # Run the operator tests in different contexts | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=lambda: None) | 
					
						
							| 
									
										
										
										
											2014-02-13 08:51:33 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 16:30:34 +00:00
										 |  |  |         if USE_FILES: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  |         run_ops(operators_test, setup_func=ctx_clear_scene) | 
					
						
							|  |  |  |         # object modes | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_object_empty) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_object_pose) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_object_paint_weight) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_object_paint_vertex) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_object_paint_sculpt) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_object_paint_texture) | 
					
						
							|  |  |  |         # mesh | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_mesh) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_mesh_extra) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_mesh_empty) | 
					
						
							|  |  |  |         # armature | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_armature) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_armature_empty) | 
					
						
							|  |  |  |         # curves | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_curves) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_curves_empty) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_surface) | 
					
						
							|  |  |  |         # other | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_mball) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_text) | 
					
						
							|  |  |  |         run_ops(operators_test, setup_func=ctx_editmode_lattice) | 
					
						
							| 
									
										
										
										
											2012-09-26 21:19:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-23 09:37:47 +00:00
										 |  |  |         if not operators_test: | 
					
						
							|  |  |  |             print("All setup functions run fine!") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     print("Finished %r" % __file__) | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2013-02-14 05:10:12 +00:00
										 |  |  |     #~ for i in range(200): | 
					
						
							|  |  |  |         #~ RANDOM_SEED[0] += 1 | 
					
						
							|  |  |  |         #~ main() | 
					
						
							| 
									
										
										
										
											2011-03-22 14:09:07 +00:00
										 |  |  |     main() |