Skip to content
Snippets Groups Projects
Commit 2a7343b8 authored by M Bouchard Guillaume's avatar M Bouchard Guillaume
Browse files

STL import/export

- can export multiple objects (all selected, not only active one)
- can import multiples stl file at once with the file selector
parent 6b83cb96
No related branches found
No related tags found
No related merge requests found
...@@ -41,12 +41,11 @@ Issues: ...@@ -41,12 +41,11 @@ Issues:
Import: Import:
- Does not handle the normal of the triangles - Does not handle the normal of the triangles
- Does not handle endien - Does not handle endien
Export:
- Does not do the object space transformation
- Export only one object (the selected one)
""" """
import itertools
import os
import bpy import bpy
from bpy.props import * from bpy.props import *
...@@ -70,17 +69,21 @@ class StlImporter(bpy.types.Operator): ...@@ -70,17 +69,21 @@ class StlImporter(bpy.types.Operator):
bl_idname = "import_mesh.stl" bl_idname = "import_mesh.stl"
bl_label = "Import STL" bl_label = "Import STL"
filepath = StringProperty(name="File Path", files = CollectionProperty(name="File Path",
description="File path used for importing " description="File path used for importing "
"the STL file", "the STL file",
maxlen=1024, type=bpy.types.OperatorFileListElement)
default="")
directory = StringProperty()
def execute(self, context): def execute(self, context):
objName = bpy.path.display_name(self.properties.filepath.split("\\")[-1].split("/")[-1]) paths = (os.path.join(self.properties.directory, name.name) for name in self.properties.files)
tris, pts = stl_utils.read_stl(self.properties.filepath)
for path in paths:
objName = bpy.path.display_name(path.split("\\")[-1].split("/")[-1])
tris, pts = stl_utils.read_stl(path)
blender_utils.create_and_link_mesh(objName, tris, pts) blender_utils.create_and_link_mesh(objName, tris, pts)
return {'FINISHED'} return {'FINISHED'}
...@@ -118,10 +121,10 @@ class StlExporter(bpy.types.Operator): ...@@ -118,10 +121,10 @@ class StlExporter(bpy.types.Operator):
default=True) default=True)
def execute(self, context): def execute(self, context):
ob = context.active_object faces = itertools.chain.from_iterable(
blender_utils.faces_from_mesh(ob, self.properties.apply_modifiers)
for ob in context.selected_objects)
faces = blender_utils.faces_from_mesh(ob,
self.properties.apply_modifiers)
stl_utils.write_stl(self.properties.filepath, faces, self.properties.ascii) stl_utils.write_stl(self.properties.filepath, faces, self.properties.ascii)
return {'FINISHED'} return {'FINISHED'}
...@@ -138,7 +141,6 @@ def menu_import(self, context): ...@@ -138,7 +141,6 @@ def menu_import(self, context):
def menu_export(self, context): def menu_export(self, context):
import os
default_path = os.path.splitext(bpy.data.filepath)[0] + ".stl" default_path = os.path.splitext(bpy.data.filepath)[0] + ".stl"
self.layout.operator(StlExporter.bl_idname, self.layout.operator(StlExporter.bl_idname,
text="Stl (.stl)").filepath = default_path text="Stl (.stl)").filepath = default_path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment