From: Mikko Rasa Date: Sat, 17 Apr 2021 17:41:10 +0000 (+0300) Subject: Refactor ExportMspGLBase into a simpler ExportHelper subclass X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=27a3dcc73777bcc53f93eaf66e90370b061d3988 Refactor ExportMspGLBase into a simpler ExportHelper subclass Copying properties from the operator to the exporter with setattr felt kind hacky. --- diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index fb7a1a7a..79575f7d 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -14,9 +14,9 @@ if "bpy" in locals(): import os import bpy -from bpy_extras.io_utils import ExportHelper +import bpy_extras -class ExportMspGLBase(ExportHelper): +class ExportHelper(bpy_extras.io_utils.ExportHelper): def set_extension(self, ext): ext_changed = (ext!=self.filename_ext) if ext_changed: @@ -25,19 +25,6 @@ class ExportMspGLBase(ExportHelper): self.filename_ext = ext return ext_changed - def execute(self, context): - exporter = self.create_exporter() - self.prepare_exporter(exporter) - exporter.export_to_file(context, self.filepath) - return {"FINISHED"} - - def create_exporter(self): - raise Exception("create_exporter must be overridden") - - def prepare_exporter(self, exporter): - for k, v in self.as_keywords().items(): - setattr(exporter, k, v) - class ExportMspGLData(bpy.types.Operator): bl_idname = "export.mspgl_data" bl_label = "Export Msp GL data" @@ -74,7 +61,7 @@ class ExportMspGLData(bpy.types.Operator): col.prop(self, "collection") col.prop(self, "shared_resources") -class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase): +class ExportMspGLAnimation(bpy.types.Operator, ExportHelper): bl_idname = "export.mspgl_animation" bl_label = "Export Msp GL animation" bl_description = "Export one or more animations in Msp GL format" @@ -90,9 +77,14 @@ class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase): super_result = super().check(context) return ext_changed or super_result - def create_exporter(self): + def execute(self, context): from .export_animation import AnimationExporter - return AnimationExporter() + exporter = AnimationExporter() + exporter.export_all = self.export_all + exporter.collection = self.collection + exporter.looping_threshold = self.looping_threshold + exporter.export_to_file(context, self.filepath) + return {'FINISHED'} def draw(self, context): col = self.layout.column() @@ -101,7 +93,7 @@ class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase): col.prop(self, "collection") col.prop(self, "looping_threshold") -class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase): +class ExportMspGLScene(bpy.types.Operator, ExportHelper): bl_idname = "export_scene.mspgl_scene" bl_label = "Export Msp GL scene" bl_description = "Export the active scene in Msp GL format" @@ -122,9 +114,15 @@ class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase): super_result = super().check(context) return ext_changed or super_result - def create_exporter(self): + def execute(self, context): from .export_scene import SceneExporter - return SceneExporter() + exporter = SceneExporter() + exporter.selected_only = self.selected_only + exporter.visible_only = self.visible_only + exporter.collection = self.collection + exporter.skip_existing = self.skip_existing + exporter.export_to_file(context, self.filepath) + return {'FINISHED'} def draw(self, context): col = self.layout.column()