Add an option to skip existing resources when exporting a scene
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Jul 2019 17:01:03 +0000 (20:01 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 3 Jul 2019 17:01:03 +0000 (20:01 +0300)
This can be helpful when exporting multiple scenes, to avoid certain
auto-generated resources being exported multiple times.

blender/io_mspgl/__init__.py
blender/io_mspgl/export_scene.py

index 43a3fac8f691270bae32a61bd9447bd2059ad5ef..4c5fa8c22ce735f4322396ed01e120ee0827e14e 100644 (file)
@@ -134,6 +134,7 @@ class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
        selected_only = bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects")
        active_layers = bpy.props.BoolProperty(name="Active layers only", description="Only export objects on the active layers", default=True)
        resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
+       skip_existing = bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
 
        def create_exporter(self):
                from .export_scene import SceneExporter
@@ -144,6 +145,8 @@ class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
                col.prop(self, "selected_only")
                col.prop(self, "active_layers")
                col.prop(self, "resource_collection")
+               if self.resource_collection:
+                       col.prop(self, "skip_existing")
 
 class ExportMspGLCamera(bpy.types.Operator, ExportMspGLBase):
        bl_idname = "export.mspgl_camera"
index b28c8e041db4c66d2d43b1dc59d95c1c77e76797..44c892d873d245729ed0c9b28191b6a20300556b 100644 (file)
@@ -6,6 +6,7 @@ class SceneExporter:
                self.selected_only = False
                self.active_layers = True
                self.resource_collection = True
+               self.skip_existing = True
                self.show_progress = True
 
        def export_to_file(self, context, out_fn):
@@ -80,6 +81,9 @@ class SceneExporter:
                                ".tex2d": "texture2d" }
                        with open(os.path.join(path, base+"_resources.mdc"), "w") as res_out:
                                for r in refs:
+                                       if self.skip_existing and os.path.exists(os.path.join(path, r.name)):
+                                               continue
+
                                        st = Statement(keywords[os.path.splitext(r.name)[1]], r.name)
                                        st.sub = r.statements
                                        st.write_to_file(res_out)