Deleting an element now also auto deletes its associated distribution ports

This commit is contained in:
Dion Moult
2022-05-06 10:38:38 +10:00
parent 92432f453d
commit 42edcda8bd
3 changed files with 22 additions and 0 deletions
@@ -57,4 +57,11 @@ class Usecase:
self.file.remove(inverse)
elif inverse.is_a("IfcRelVoidsElement"):
self.file.remove(inverse)
elif inverse.is_a("IfcRelNests"):
if inverse.RelatingObject == self.settings["product"]:
for subelement in inverse.RelatedObjects:
if subelement.is_a("IfcDistributionPort"):
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
if not inverse.RelatedObjects:
self.file.remove(inverse)
self.file.remove(self.settings["product"])
@@ -130,3 +130,13 @@ class TestRemoveProduct(test.bootstrap.IFC4):
assert len(list(self.file)) == total_entities - 2
assert len(self.file.by_type("IfcDoor")) == 0
assert len(self.file.by_type("IfcRelFillsElement")) == 0
def test_removing_all_distribution_ports(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
port = ifcopenshell.api.run("system.add_port", self.file, element=element)
total_entities = len(list(self.file))
ifcopenshell.api.run("root.remove_product", self.file, product=element)
assert len(list(self.file)) == total_entities - 3
assert len(self.file.by_type("IfcChiller")) == 0
assert len(self.file.by_type("IfcRelNests")) == 0
assert len(self.file.by_type("IfcDistributionPort")) == 0