BIM: Fixed missing object creation in IFC document conversion (#17093)

* BIM: Fixed missing object creation in IFC document conversion - fixes #17031

* BIM: fixed deleting of non-existing objects - fixes #17032
This commit is contained in:
Yorik van Havre
2024-10-14 17:37:31 +02:00
committed by GitHub
parent df8c9d5def
commit 7dc6152a5f
2 changed files with 31 additions and 17 deletions

View File

@@ -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(),

View File

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