diff --git a/src/Mod/BIM/importers/exportIFC.py b/src/Mod/BIM/importers/exportIFC.py index 76e21a79e6..ff3586af8e 100644 --- a/src/Mod/BIM/importers/exportIFC.py +++ b/src/Mod/BIM/importers/exportIFC.py @@ -1106,22 +1106,22 @@ def export(exportList, filename, colors=None, preferences=None): None, None )] - if buildings and (not sites): - ifcfile.createIfcRelAggregates( - ifcopenshell.guid.new(), - history, - 'ProjectLink', - '', - project,buildings - ) - if floors and buildings: - ifcfile.createIfcRelAggregates( - ifcopenshell.guid.new(), - history, - 'BuildingLink', - '', - buildings[0],floors - ) + if buildings and (not sites): + ifcfile.createIfcRelAggregates( + ifcopenshell.guid.new(), + history, + 'ProjectLink', + '', + project,buildings + ) + if floors and buildings: + ifcfile.createIfcRelAggregates( + ifcopenshell.guid.new(), + history, + 'BuildingLink', + '', + buildings[0],floors + ) if sites and buildings: ifcfile.createIfcRelAggregates( ifcopenshell.guid.new(), diff --git a/src/Mod/BIM/nativeifc/ifc_status.py b/src/Mod/BIM/nativeifc/ifc_status.py index 573923855c..777664e1fd 100644 --- a/src/Mod/BIM/nativeifc/ifc_status.py +++ b/src/Mod/BIM/nativeifc/ifc_status.py @@ -193,6 +193,7 @@ def lock_document(): doc = FreeCAD.ActiveDocument products = [] spatial = [] + ifcfile = None if "IfcFilePath" not in doc.PropertiesList: # this is not a locked document projects = [o for o in doc.Objects if getattr(o, "Class", None) == "IfcProject"] @@ -249,7 +250,8 @@ def lock_document(): prefs, context = ifc_tools.get_export_preferences(ifcfile) exportIFC.export(objs, ifcfile, preferences=prefs) for n in [o.Name for o in doc.Objects]: - doc.removeObject(n) + if doc.getObject(n): + doc.removeObject(n) ifc_tools.create_children(doc, ifcfile, recursive=True) doc.Modified = True doc.commitTransaction() @@ -260,6 +262,18 @@ def lock_document(): ifc_tools.convert_document(doc) doc.commitTransaction() doc.recompute() + # reveal file contents if needed + if "IfcFilePath" in doc.PropertiesList: + create = True + for o in doc.Objects: + # scan for site or building + if getattr(o, "IfcClass", "") in ("IfcSite", "IfcBuilding"): + create = False + break + if create: + if not ifcfile: + ifcfile = doc.Proxy.ifcfile + ifc_tools.create_children(doc, recursive=False) def find_toplevel(objs):