Skip to content

Commit

Permalink
Add error catching to model loading and let users hide error dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult committed May 9, 2024
1 parent 2789bc5 commit 4c8f93d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/blenderbim/blenderbim/bim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
operator.BIM_OT_select_object,
operator.BIM_OT_show_description,
operator.ClippingPlaneCutWithCappings,
operator.CloseError,
operator.EditBlenderCollection,
operator.FileAssociate,
operator.FileUnassociate,
Expand Down
27 changes: 16 additions & 11 deletions src/blenderbim/blenderbim/bim/module/project/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import time
import logging
import tempfile
import traceback
import subprocess
import numpy as np
import ifcopenshell
Expand Down Expand Up @@ -674,19 +675,23 @@ def load_handler(*args):
return self.finish_loading_project(context)

def finish_loading_project(self, context):
if not self.is_existing_ifc_file():
return {"FINISHED"}
try:
if not self.is_existing_ifc_file():
return {"FINISHED"}

if tool.Blender.is_default_scene():
for obj in bpy.data.objects:
bpy.data.objects.remove(obj)
if tool.Blender.is_default_scene():
for obj in bpy.data.objects:
bpy.data.objects.remove(obj)

context.scene.BIMProperties.ifc_file = self.get_filepath()
context.scene.BIMProjectProperties.is_loading = True
context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement"))
tool.Blender.register_toolbar()
if not self.is_advanced:
bpy.ops.bim.load_project_elements()
context.scene.BIMProperties.ifc_file = self.get_filepath()
context.scene.BIMProjectProperties.is_loading = True
context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement"))
tool.Blender.register_toolbar()
if not self.is_advanced:
bpy.ops.bim.load_project_elements()
except:
blenderbim.last_error = traceback.format_exc()
raise
return {"FINISHED"}

def invoke(self, context, event):
Expand Down
9 changes: 9 additions & 0 deletions src/blenderbim/blenderbim/bim/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def execute(self, context):
return {"FINISHED"}


class CloseError(bpy.types.Operator):
bl_idname = "bim.close_error"
bl_label = "Close Error"

def execute(self, context):
blenderbim.last_error = None
return {"FINISHED"}


class SelectURIAttribute(bpy.types.Operator):
bl_idname = "bim.select_uri_attribute"
bl_label = "Select URI Attribute"
Expand Down
4 changes: 3 additions & 1 deletion src/blenderbim/blenderbim/bim/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ def draw(self, context):

if blenderbim.last_error:
box = self.layout.box()
box.label(text="BlenderBIM experienced an error :(", icon="ERROR")
row = box.row(align=True)
row.label(text="BlenderBIM experienced an error :(", icon="ERROR")
row.operator("bim.close_error", text="", icon="CANCEL")
box.label(text="View the console for full logs.", icon="CONSOLE")
box.operator("bim.copy_debug_information", text="Copy Error Message To Clipboard")
op = box.operator("bim.open_uri", text="How Can I Fix This?")
Expand Down

0 comments on commit 4c8f93d

Please sign in to comment.