From 3dd184d9da5503b56c6b6063b7f8b782dc85d92c Mon Sep 17 00:00:00 2001 From: tritao Date: Wed, 5 Feb 2025 00:46:54 +0000 Subject: [PATCH] BIM: Improve checking of IfcOpenShell imports in `ifc_tools.py` . --- src/Mod/BIM/nativeifc/ifc_tools.py | 36 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Mod/BIM/nativeifc/ifc_tools.py b/src/Mod/BIM/nativeifc/ifc_tools.py index bc1599e0a8..de90414a5b 100644 --- a/src/Mod/BIM/nativeifc/ifc_tools.py +++ b/src/Mod/BIM/nativeifc/ifc_tools.py @@ -23,22 +23,34 @@ """This is the main NativeIFC module""" import os - -# heavyweight libraries - ifc_tools should always be lazy loaded - import FreeCAD import Draft import Arch -import ifcopenshell -from ifcopenshell import geom -from ifcopenshell import api -from ifcopenshell import template -from ifcopenshell.util import element -from ifcopenshell.util import attribute -from ifcopenshell.util import schema -from ifcopenshell.util import placement -from ifcopenshell.util import unit +translate = FreeCAD.Qt.translate + +# heavyweight libraries - ifc_tools should always be lazy loaded + +try: + import ifcopenshell + from ifcopenshell import geom + from ifcopenshell import api + from ifcopenshell import template + from ifcopenshell.util import element + from ifcopenshell.util import attribute + from ifcopenshell.util import schema + from ifcopenshell.util import placement + from ifcopenshell.util import unit +except ImportError as e: + import FreeCAD + FreeCAD.Console.PrintError( + translate( + "BIM", + "IfcOpenShell was not found on this system. IFC support is disabled", + ) + + "\n" + ) + raise e from nativeifc import ifc_objects from nativeifc import ifc_viewproviders