From 3defef03c6fa696fadd6f5ea37072ae98e53b74c Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 25 Mar 2024 17:29:33 +0100 Subject: [PATCH] Arch: Allow to write IFC objects without owner history (#13076) * Arch: Allow to write IFC objects without owner history * Arch: Fixed context detection in IFC exporter --- src/Mod/Arch/exportIFC.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Mod/Arch/exportIFC.py b/src/Mod/Arch/exportIFC.py index d940b7c249..e168c3bf93 100644 --- a/src/Mod/Arch/exportIFC.py +++ b/src/Mod/Arch/exportIFC.py @@ -265,7 +265,12 @@ def export(exportList, filename, colors=None, preferences=None): ifcfile = ifcopenshell.open(templatefile) ifcfile = exportIFCHelper.writeUnits(ifcfile,preferences["IFC_UNIT"]) - history = ifcfile.by_type("IfcOwnerHistory")[0] + history = ifcfile.by_type("IfcOwnerHistory") + if history: + history = history[0] + else: + # IFC4 allows to not write any history + history = None objectslist = Draft.get_group_contents(exportList, walls=True, addgroups=True) @@ -296,7 +301,9 @@ def export(exportList, filename, colors=None, preferences=None): if existing_file: project = ifcfile.by_type("IfcProject")[0] - context = ifcfile.by_type("IFcGeometricRepresentationContext")[-1] + body_contexts = [c for c in ifcfile.by_type("IfcGeometricRepresentationSubContext") if c.ContextIdentifier in ["Body", "Facetation"]] + body_contexts.extend([c for c in ifcfile.by_type("IfcGeometricRepresentationContext", include_subtypes=False) if c.ContextType == "Model"]) + context = body_contexts[0] # we take the first one (subcontext if existing, or context if not) else: contextCreator = exportIFCHelper.ContextCreator(ifcfile, objectslist) context = contextCreator.model_view_subcontext