[Bf-extensions-cvs] [77784ac] master: Batch-export for STL

Campbell Barton noreply at git.blender.org
Mon Oct 26 19:12:30 CET 2015


Commit: 77784acf17fa95033832307ddf416964b80ca43d
Author: Campbell Barton
Date:   Tue Oct 27 04:51:58 2015 +1100
Branches: master
https://developer.blender.org/rBA77784acf17fa95033832307ddf416964b80ca43d

Batch-export for STL

Original patch by D1582 by @lichtwerk

Also added 'use_selection' option, matching other exporters.

===================================================================

M	io_mesh_stl/__init__.py

===================================================================

diff --git a/io_mesh_stl/__init__.py b/io_mesh_stl/__init__.py
index b08b3f7..e669659 100644
--- a/io_mesh_stl/__init__.py
+++ b/io_mesh_stl/__init__.py
@@ -163,6 +163,11 @@ class ExportSTL(Operator, ExportHelper, IOSTLOrientationHelper):
     filename_ext = ".stl"
     filter_glob = StringProperty(default="*.stl", options={'HIDDEN'})
 
+    use_selection = BoolProperty(
+            name="Selection Only",
+            description="Export selected objects only",
+            default=False,
+            )
     global_scale = FloatProperty(
             name="Scale",
             min=0.01, max=1000.0,
@@ -184,7 +189,15 @@ class ExportSTL(Operator, ExportHelper, IOSTLOrientationHelper):
             description="Apply the modifiers before saving",
             default=True,
             )
+    batch_mode = EnumProperty(
+            name="Batch Mode",
+            items=(('OFF', "Off", "All data in one file"),
+                   ('OBJECT', "Object", "Each object as a file"),
+                   ))
 
+    @property
+    def check_extension(self):
+        return self.batch_mode == 'OFF'
 
     def execute(self, context):
         from . import stl_utils
@@ -193,14 +206,20 @@ class ExportSTL(Operator, ExportHelper, IOSTLOrientationHelper):
         from mathutils import Matrix
         keywords = self.as_keywords(ignore=("axis_forward",
                                             "axis_up",
+                                            "use_selection",
                                             "global_scale",
                                             "check_existing",
                                             "filter_glob",
                                             "use_scene_unit",
                                             "use_mesh_modifiers",
+                                            "batch_mode"
                                             ))
 
         scene = context.scene
+        if self.use_selection:
+            data_seq = context.selected_objects
+        else:
+            data_seq = scene.objects
 
         # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000.
         global_scale = self.global_scale
@@ -211,11 +230,19 @@ class ExportSTL(Operator, ExportHelper, IOSTLOrientationHelper):
                                         to_up=self.axis_up,
                                         ).to_4x4() * Matrix.Scale(global_scale, 4)
 
-        faces = itertools.chain.from_iterable(
-            blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers)
-            for ob in context.selected_objects)
-
-        stl_utils.write_stl(faces=faces, **keywords)
+        if self.batch_mode == 'OFF':
+            faces = itertools.chain.from_iterable(
+                    blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers)
+                    for ob in data_seq)
+
+            stl_utils.write_stl(faces=faces, **keywords)
+        elif self.batch_mode == 'OBJECT':
+            prefix = os.path.splitext(self.filepath)[0]
+            keywords_temp = keywords.copy()
+            for ob in data_seq:
+                faces = blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers)
+                keywords_temp["filepath"] = prefix + bpy.path.clean_name(ob.name) + ".stl"
+                stl_utils.write_stl(faces=faces, **keywords_temp)
 
         return {'FINISHED'}



More information about the Bf-extensions-cvs mailing list