fix removing references in ifc2x3 #4636

This commit is contained in:
Andrej730
2024-05-08 15:12:45 +05:00
parent d4ccadb832
commit c5a7a8680e
2 changed files with 11 additions and 3 deletions
@@ -38,11 +38,15 @@ def remove_reference(file: ifcopenshell.file, reference: ifcopenshell.entity_ins
reference = ifcopenshell.api.run("document.add_reference", model, information=document)
ifcopenshell.api.run("document.remove_reference", model, reference=reference)
"""
settings = {"reference": reference}
for rel in settings["reference"].DocumentRefForObjects or []:
if file.schema == "IFC2X3":
rels = [r for r in file.get_inverse(reference) if r.is_a("IfcRelAssociatesDocument")]
else:
rels = reference.DocumentRefForObjects
for rel in rels:
history = rel.OwnerHistory
file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(file, history)
file.remove(settings["reference"])
file.remove(reference)
@@ -41,3 +41,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcDocumentReference")) == 0
assert len(self.file.by_type("IfcDocumentInformation")) == 1
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1
class TestRemoveReferenceIFC2X3(test.bootstrap.IFC2X3, TestRemoveReference):
pass