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
This commit is contained in:
Yorik van Havre
2024-03-25 17:29:33 +01:00
committed by GitHub
parent e5d4f0e38e
commit 3defef03c6

View File

@@ -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