diff --git a/src/ifcopenshell-python/ifcopenshell/api/void/add_filling.py b/src/ifcopenshell-python/ifcopenshell/api/void/add_filling.py index 33784b4cfa..64fee4a19e 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/void/add_filling.py +++ b/src/ifcopenshell-python/ifcopenshell/api/void/add_filling.py @@ -9,6 +9,13 @@ class Usecase: self.settings[key] = value def execute(self): + fills_voids = self.settings["element"].FillsVoids + + if fills_voids: + if fills_voids[0].RelatingOpeningElement == self.settings["opening"]: + return + self.file.remove(fills_voids[0]) + self.file.create_entity( "IfcRelFillsElement", **{ diff --git a/src/ifcopenshell-python/test/api/void/test_add_filling.py b/src/ifcopenshell-python/test/api/void/test_add_filling.py new file mode 100644 index 0000000000..b3d5bbf0cb --- /dev/null +++ b/src/ifcopenshell-python/test/api/void/test_add_filling.py @@ -0,0 +1,27 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestAddFilling(test.bootstrap.IFC4): + def test_adding_a_filling(self): + opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement") + door = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor") + ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=door) + assert door.FillsVoids[0].RelatingOpeningElement == opening + + def test_adding_a_filling_twice(self): + opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement") + door = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor") + ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=door) + ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=door) + assert door.FillsVoids[0].RelatingOpeningElement == opening + assert len(opening.HasFillings) == 1 + + def test_adding_a_filling_which_is_already_filling_another_opening(self): + door = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor") + opening1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement") + opening2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement") + ifcopenshell.api.run("void.add_filling", self.file, opening=opening1, element=door) + ifcopenshell.api.run("void.add_filling", self.file, opening=opening2, element=door) + assert not opening1.HasFillings + assert opening2.HasFillings[0].RelatedBuildingElement == door