Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-10-26 20:51:58 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-10-26 21:06:43 +0300
commit77784acf17fa95033832307ddf416964b80ca43d (patch)
tree4b3e61a42658f885a4b8f8a7432a054ae4fdf70f /io_mesh_stl
parent00f61a72b54d4abb5e692451cad3f8fd3925314e (diff)
Batch-export for STL
Original patch by D1582 by @lichtwerk Also added 'use_selection' option, matching other exporters.
Diffstat (limited to 'io_mesh_stl')
-rw-r--r--io_mesh_stl/__init__.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/io_mesh_stl/__init__.py b/io_mesh_stl/__init__.py
index b08b3f7c..e669659d 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'}