Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions import_3dm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion import_3dm/read3dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:

Expand All @@ -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:
Expand Down