From dbaf19b442b79a70d33c985c24de1681555b0586 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 21 Mar 2022 16:26:43 +0100 Subject: [PATCH] Arch: Fixed IFC export of compounds and parts --- src/Mod/Arch/exportIFC.py | 76 +++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/src/Mod/Arch/exportIFC.py b/src/Mod/Arch/exportIFC.py index b64fc6bdde..38e2c3bb15 100644 --- a/src/Mod/Arch/exportIFC.py +++ b/src/Mod/Arch/exportIFC.py @@ -341,6 +341,10 @@ def export(exportList, filename, colors=None, preferences=None): for obj in objectslist: + if obj.Name in products: + # never export same product twice + continue + # structural analysis object structobj = None @@ -413,31 +417,39 @@ def export(exportList, filename, colors=None, preferences=None): # the own Shape is ignored if representation is retrieved # this because we will build an assembly for the assemblyElements # from here and the assembly itself should not have a representation - - elif ifctype == "IfcApp::Part": - for subobj in [FreeCAD.ActiveDocument.getObject(n[:-1]) for n in obj.getSubObjects()]: - representation,placement,shapetype = getRepresentation( - ifcfile, - context, - subobj, - forcebrep=(getBrepFlag(subobj,preferences)), - colors=colors, - preferences=preferences - ) - subproduct = createProduct( - ifcfile, - subobj, - getIfcTypeFromObj(subobj), - getUID(subobj,preferences), - history, - getText("Name",subobj), - getText("Description",subobj), - placement, - representation, - preferences) - + if ifctype in ["IfcApp::Part","IfcPart::Compound","IfcElementAssembly"]: + if hasattr(obj,"Group"): + group = obj.Group + elif hasattr(obj,"Links"): + group = obj.Links + else: + group = [FreeCAD.ActiveDocument.getObject(n[:-1]) for n in obj.getSubObjects()] + for subobj in group: + if subobj.Name in products: + subproduct = products[subobj.Name] + else: + representation,placement,shapetype = getRepresentation( + ifcfile, + context, + subobj, + forcebrep=(getBrepFlag(subobj,preferences)), + colors=colors, + preferences=preferences + ) + subproduct = createProduct( + ifcfile, + subobj, + getIfcTypeFromObj(subobj), + getUID(subobj,preferences), + history, + getText("Name",subobj), + getText("Description",subobj), + placement, + representation, + preferences) + products[obj.Name] = subproduct assemblyElements.append(subproduct) - ifctype = "IfcElementAssembly" + ifctype = "IfcElementAssembly" # export grids @@ -1679,21 +1691,23 @@ def isStandardCase(obj,ifctype): def getIfcTypeFromObj(obj): - if (Draft.getType(obj) == "BuildingPart") and hasattr(obj,"IfcType") and (obj.IfcType == "Undefined"): + dtype = Draft.getType(obj) + if (dtype == "BuildingPart") and hasattr(obj,"IfcType") and (obj.IfcType == "Undefined"): ifctype = "IfcBuildingStorey" # export BuildingParts as Storeys if their type wasn't explicitly set elif hasattr(obj,"IfcType"): ifctype = obj.IfcType.replace(" ","") + elif dtype in ["App::Part","Part::Compound"]: + ifctype = "IfcElementAssembly" + elif dtype in ["App::DocumentObjctGroup"]: + ifctype = "IfcGroup" else: - ifctype = Draft.getType(obj) + ifctype = dtype if ifctype in translationtable.keys(): ifctype = translationtable[ifctype] - - if "::" not in ifctype: + if not ifctype.startswith("Ifc"): ifctype = "Ifc" + ifctype - elif ifctype == "IfcApp::DocumentObjctGroup": - ifctype = "IfcGroup" - else: + if "::" in ifctype: # it makes no sense to return IfcPart::Cylinder for a Part::Cylinder # this is not a ifctype at all ifctype = None