diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_product.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_product.py index afc29f5d64..4437913ffc 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_product.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_product.py @@ -16,7 +16,7 @@ class Usecase: if self.settings["related_object"].HasAssignments: for assignment in self.settings["related_object"].HasAssignments: if ( - assignment.is_a("IfclRelAssignsToProduct") + assignment.is_a("IfcRelAssignsToProduct") and assignment.RelatingProduct == self.settings["relating_product"] ): return diff --git a/src/ifcopenshell-python/test/api/library/test_unassign_reference.py b/src/ifcopenshell-python/test/api/library/test_unassign_reference.py index 4e2b651928..6c31a05c08 100644 --- a/src/ifcopenshell-python/test/api/library/test_unassign_reference.py +++ b/src/ifcopenshell-python/test/api/library/test_unassign_reference.py @@ -6,7 +6,6 @@ class TestUnassignReference(test.bootstrap.IFC4): def test_unassigning_a_reference(self): reference = self.file.createIfcLibraryReference() product = self.file.createIfcWall() - product2 = self.file.createIfcWall() ifcopenshell.api.run("library.assign_reference", self.file, product=product, reference=reference) ifcopenshell.api.run("library.unassign_reference", self.file, product=product, reference=reference) assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0 diff --git a/src/ifcopenshell-python/test/api/sequence/test_assign_product.py b/src/ifcopenshell-python/test/api/sequence/test_assign_product.py new file mode 100644 index 0000000000..d2777a4bf2 --- /dev/null +++ b/src/ifcopenshell-python/test/api/sequence/test_assign_product.py @@ -0,0 +1,20 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestAssignProduct(test.bootstrap.IFC4): + def test_assigning_a_product(self): + wall = self.file.createIfcWall() + task = self.file.createIfcTask() + task2 = self.file.createIfcTask() + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task) + assert wall.ReferencedBy[0].RelatedObjects == (task,) + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task2) + assert wall.ReferencedBy[0].RelatedObjects == (task, task2) + + def test_not_assigning_twice(self): + wall = self.file.createIfcWall() + task = self.file.createIfcTask() + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task) + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task) + assert wall.ReferencedBy[0].RelatedObjects == (task,) diff --git a/src/ifcopenshell-python/test/api/sequence/test_unassign_product.py b/src/ifcopenshell-python/test/api/sequence/test_unassign_product.py new file mode 100644 index 0000000000..4ca994143c --- /dev/null +++ b/src/ifcopenshell-python/test/api/sequence/test_unassign_product.py @@ -0,0 +1,11 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestUnassignProduct(test.bootstrap.IFC4): + def test_unassigning_a_product(self): + wall = self.file.createIfcWall() + task = self.file.createIfcTask() + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task) + ifcopenshell.api.run("sequence.unassign_product", self.file, relating_product=wall, related_object=task) + assert len(self.file.by_type("IfcRelAssignsToProduct")) == 0