diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-12-24 10:46:40 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-12-24 10:46:40 +0300 |
commit | 4d0c10d5ca9f2fb03a6183e77ed0265ed2218cae (patch) | |
tree | 1bbf438029cb2e01bddcdbc0dce093b04489009f /release | |
parent | c0339029c76b53461edad9ab2ebdae4bce61dfee (diff) |
presets for operators, re-using same preset system as render, cloth etc use.
- operators need to enable the option OPTYPE_PRESET or 'PRESET' in python.
- hidden properties are not written.
- currently this only works in the file selector (enabled for FBX/OBJ export)
- currently the menu label doesnt change when presets are selected, this is a TODO, not so simple since the UI is defined in C and the label in python.
- presets save in "scripts/presets/operators/*id*/*.py"
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/op/io_scene_fbx/__init__.py | 1 | ||||
-rw-r--r-- | release/scripts/op/io_scene_obj/__init__.py | 1 | ||||
-rw-r--r-- | release/scripts/op/presets.py | 51 |
3 files changed, 53 insertions, 0 deletions
diff --git a/release/scripts/op/io_scene_fbx/__init__.py b/release/scripts/op/io_scene_fbx/__init__.py index baf7e78014a..6a76cf0d756 100644 --- a/release/scripts/op/io_scene_fbx/__init__.py +++ b/release/scripts/op/io_scene_fbx/__init__.py @@ -34,6 +34,7 @@ class ExportFBX(bpy.types.Operator, ExportHelper): '''Selection to an ASCII Autodesk FBX''' bl_idname = "export_scene.fbx" bl_label = "Export FBX" + bl_options = {'PRESET'} filename_ext = ".fbx" filter_glob = StringProperty(default="*.fbx", options={'HIDDEN'}) diff --git a/release/scripts/op/io_scene_obj/__init__.py b/release/scripts/op/io_scene_obj/__init__.py index 8a35bb81dd9..b87c6b44347 100644 --- a/release/scripts/op/io_scene_obj/__init__.py +++ b/release/scripts/op/io_scene_obj/__init__.py @@ -65,6 +65,7 @@ class ExportOBJ(bpy.types.Operator, ExportHelper): bl_idname = "export_scene.obj" bl_label = 'Export OBJ' + bl_options = {'PRESET'} filename_ext = ".obj" filter_glob = StringProperty(default="*.obj;*.mtl", options={'HIDDEN'}) diff --git a/release/scripts/op/presets.py b/release/scripts/op/presets.py index b0dd7de3f1c..dd16a4ee5e0 100644 --- a/release/scripts/op/presets.py +++ b/release/scripts/op/presets.py @@ -301,6 +301,57 @@ class AddPresetKeyconfig(AddPresetBase, bpy.types.Operator): keyconfigs.remove(keyconfigs.active) +class AddPresetOperator(AddPresetBase, bpy.types.Operator): + '''Add an Application Interaction Preset''' + bl_idname = "wm.operator_preset_add" + bl_label = "Operator Preset" + preset_menu = "WM_MT_operator_presets" + + operator = bpy.props.StringProperty(name="Operator", maxlen=64, options={'HIDDEN'}) + + # XXX, not ideal + preset_defines = [ + "op = bpy.context.space_data.operator", + ] + + @property + def preset_subdir(self): + return __class__.operator_path(self.operator) + + @property + def preset_values(self): + properties_blacklist = bpy.types.Operator.bl_rna.properties.keys() + + prefix, suffix = self.operator.split("_OT_", 1) + operator_rna = getattr(getattr(bpy.ops, prefix.lower()), suffix).get_rna().bl_rna + + ret = [] + for prop_id, prop in operator_rna.properties.items(): + if (not prop.is_hidden) and prop_id not in properties_blacklist: + ret.append("op.%s" % prop_id) + + return ret + + @staticmethod + def operator_path(operator): + import os + prefix, suffix = operator.split("_OT_", 1) + return os.path.join("operator", "%s.%s" % (prefix.lower(), suffix)) + + +class WM_MT_operator_presets(bpy.types.Menu): + bl_label = "Operator Presets" + + def draw(self, context): + self.operator = context.space_data.operator.bl_idname + bpy.types.Menu.draw_preset(self, context) + + @property + def preset_subdir(self): + return AddPresetOperator.operator_path(self.operator) + + preset_operator = "script.execute_preset" + def register(): pass |