diff --git a/io_mesh_stl/__init__.py b/io_mesh_stl/__init__.py index 41765d2c0a0a0e1cfcfc7dcd6bfac8d06d850920..24e1650d0ba5be4fb09d7d797ce51b7b867bf60e 100644 --- a/io_mesh_stl/__init__.py +++ b/io_mesh_stl/__init__.py @@ -77,7 +77,7 @@ class ImportSTL(bpy.types.Operator, ImportHelper): "the STL file", type=bpy.types.OperatorFileListElement) - directory = StringProperty() + directory = StringProperty(subtype='DIR_PATH') def execute(self, context): from . import stl_utils @@ -88,8 +88,14 @@ class ImportSTL(bpy.types.Operator, ImportHelper): if not paths: paths.append(self.filepath) + if bpy.ops.object.mode_set.poll(): + bpy.ops.object.mode_set(mode='OBJECT') + + if bpy.ops.object.select_all.poll(): + bpy.ops.object.select_all(action='DESELECT') + for path in paths: - objName = bpy.path.display_name(path.split("\\")[-1].split("/")[-1]) + objName = bpy.path.display_name(os.path.basename(path)) tris, pts = stl_utils.read_stl(path) blender_utils.create_and_link_mesh(objName, tris, pts) diff --git a/io_mesh_stl/blender_utils.py b/io_mesh_stl/blender_utils.py index 1058064b01e47ba69447464d446e4f2ddc63f6ab..8d19e30ce369104fbfdba3ea0b8e1916afa9d076 100644 --- a/io_mesh_stl/blender_utils.py +++ b/io_mesh_stl/blender_utils.py @@ -30,13 +30,16 @@ def create_and_link_mesh(name, faces, points): mesh = bpy.data.meshes.new(name) mesh.from_pydata(points, [], faces) - ob = bpy.data.objects.new(name, mesh) - bpy.context.scene.objects.link(ob) - # update mesh to allow proper display mesh.validate() mesh.update() + scene = bpy.context.scene + + obj = bpy.data.objects.new(name, mesh) + scene.objects.link(obj) + obj.select = True + def faces_from_mesh(ob, apply_modifier=False, triangulate=True): '''