diff --git a/import_3dm/__init__.py b/import_3dm/__init__.py index cd36b53..a32b9d0 100644 --- a/import_3dm/__init__.py +++ b/import_3dm/__init__.py @@ -39,7 +39,7 @@ import bpy # ImportHelper is a helper class, defines filename and # invoke() function which calls the file selector. -from bpy_extras.io_utils import ImportHelper +from bpy_extras.io_utils import ImportHelper, poll_file_object_drop from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty from bpy.types import Operator @@ -52,6 +52,7 @@ class Import3dm(Operator, ImportHelper): """Import Rhinoceros 3D files (.3dm). Currently does render meshes only, more geometry and data to follow soon.""" bl_idname = "import_3dm.some_data" # important since its how bpy.ops.import_3dm.some_data is constructed bl_label = "Import Rhinoceros 3D file" + bl_options = {'REGISTER', 'UNDO'} # ImportHelper mixin class uses this filename_ext = ".3dm" @@ -207,32 +208,9 @@ class Import3dm(Operator, ImportHelper): ) # type: ignore def execute(self, context : bpy.types.Context): - options : Dict[str, Any] = { - "filepath":self.filepath, - "import_views":self.import_views, - "import_named_views":self.import_named_views, - "import_annotations":self.import_annotations, - "import_curves":self.import_curves, - "import_meshes":self.import_meshes, - "import_subd":self.import_subd, - "import_extrusions":self.import_extrusions, - "import_brep":self.import_brep, - "import_pointset":self.import_pointset, - "update_materials":self.update_materials, - "import_hidden_objects":self.import_hidden_objects, - "import_hidden_layers":self.import_hidden_layers, - "import_layers_as_empties": self.import_layers_as_empties, - "import_groups":self.import_groups, - "import_nested_groups":self.import_nested_groups, - "import_instances":self.import_instances, - "import_instances_grid_layout":self.import_instances_grid_layout, - "import_instances_grid":self.import_instances_grid, - "link_materials_to":self.link_materials_to, - "subD_level_viewport":self.subD_level_viewport, - "subD_level_render":self.subD_level_render, - "subD_boundary_smooth":self.subD_boundary_smooth, - } - return read_3dm(context, options) + options = self.as_keywords() + # Single file import + return read_3dm(context, self.filepath, options) def draw(self, _ : bpy.types.Context): layout = self.layout @@ -287,6 +265,24 @@ def draw(self, _ : bpy.types.Context): box.prop(self, "subD_level_viewport") box.prop(self, "subD_level_render") box.prop(self, "subD_boundary_smooth") + + def invoke(self, context, event): + self.files = [] + return ImportHelper.invoke_popup(self, context) + + +class IO_FH_3dm_import(bpy.types.FileHandler): + bl_idname = "IO_FH_3dm_import" + bl_label = "File handler for Rhinoceros 3D file import" + bl_import_operator = "import_3dm.some_data" + bl_file_extensions = ".3dm" + + @classmethod + def poll_drop(cls, context): + return poll_file_object_drop(context) + + + # Only needed if you want to add into a dynamic menu def menu_func_import(self, _ : bpy.types.Context): @@ -295,11 +291,13 @@ def menu_func_import(self, _ : bpy.types.Context): def register(): bpy.utils.register_class(Import3dm) + bpy.utils.register_class(IO_FH_3dm_import) bpy.types.TOPBAR_MT_file_import.append(menu_func_import) def unregister(): bpy.utils.unregister_class(Import3dm) + bpy.utils.unregister_class(IO_FH_3dm_import) bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) diff --git a/import_3dm/read3dm.py b/import_3dm/read3dm.py index c6cc8b6..085fabc 100644 --- a/import_3dm/read3dm.py +++ b/import_3dm/read3dm.py @@ -66,6 +66,7 @@ def create_or_get_top_layer(context, filepath): def read_3dm( context : bpy.types.Context, + filepath : str, options : Dict[str, Any] ) -> Set[str]: @@ -89,7 +90,6 @@ def read_3dm( import_instances = options.get("import_instances",False) update_materials = options.get("update_materials", False) - filepath : str = options.get("filepath", "") model = None try: