From 242d2cb4efbd4eafe93639e8b95da4bf9e6d4af9 Mon Sep 17 00:00:00 2001 From: rileywong311 Date: Tue, 1 Aug 2023 21:54:00 -0700 Subject: [PATCH] Guard loading brick files from bad paths Referred to "IFCFileSelector.is_existing_ifc_file" method for to make this --- src/blenderbim/blenderbim/bim/module/brick/operator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/brick/operator.py b/src/blenderbim/blenderbim/bim/module/brick/operator.py index 0bdddcb370..f63a09a59d 100644 --- a/src/blenderbim/blenderbim/bim/module/brick/operator.py +++ b/src/blenderbim/blenderbim/bim/module/brick/operator.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . +import os import bpy import ifcopenshell.api import blenderbim.tool as tool @@ -40,8 +41,11 @@ class LoadBrickProject(bpy.types.Operator, Operator): filter_glob: bpy.props.StringProperty(default="*.ttl", options={"HIDDEN"}) def _execute(self, context): - root = context.scene.BIMBrickProperties.brick_list_root - core.load_brick_project(tool.Brick, filepath=self.filepath, brick_root=root) + if os.path.exists(self.filepath) and "ttl" in os.path.splitext(self.filepath)[1].lower(): + root = context.scene.BIMBrickProperties.brick_list_root + core.load_brick_project(tool.Brick, filepath=self.filepath, brick_root=root) + else: + self.report({'ERROR'}, f'Failed to load {self.filepath}') def invoke(self, context, event): context.window_manager.fileselect_add(self)