diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py index e71138702c..caad38bb05 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py @@ -83,6 +83,9 @@ class Usecase: elif getattr(self.settings["product"], "Nests", None): relating_object = self.settings["product"].Nests[0].RelatingObject return relating_object.ObjectPlacement if hasattr(relating_object, "ObjectPlacement") else None + elif getattr(self.settings["product"], "ContainedIn", None): + related_element = self.settings["product"].ContainedIn[0].RelatedElement + return related_element.ObjectPlacement if hasattr(related_element, "ObjectPlacement") else None elif getattr(self.settings["product"], "VoidsElements", None): relating_object = self.settings["product"].VoidsElements[0].RelatingBuildingElement return relating_object.ObjectPlacement if hasattr(relating_object, "ObjectPlacement") else None diff --git a/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py b/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py index 56d1a674c9..384c5fc5d3 100644 --- a/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py +++ b/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py @@ -459,3 +459,36 @@ class TestEditObjectPlacement(test.bootstrap.IFC4): assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix) assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), submatrix) assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement + + +class TestEditObjectPlacement(test.bootstrap.IFC2X3): + def test_changing_placements_relative_to_a_distribution_element(self): + ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject") + ifcopenshell.api.run("unit.assign_unit", self.file) + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment") + subelement = ifcopenshell.api.run("system.add_port", self.file, element=element) + matrix = numpy.array( + ( + (1.0, 0.0, 0.0, 1.0), + (0.0, 1.0, 0.0, 1.0), + (0.0, 0.0, 1.0, 1.0), + (0.0, 0.0, 0.0, 1.0), + ) + ) + submatrix = numpy.array( + ( + (1.0, 0.0, 0.0, 1.0), + (0.0, 1.0, 0.0, 2.0), + (0.0, 0.0, 1.0, 3.0), + (0.0, 0.0, 0.0, 1.0), + ) + ) + ifcopenshell.api.run( + "geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False + ) + ifcopenshell.api.run( + "geometry.edit_object_placement", self.file, product=subelement, matrix=submatrix.copy(), is_si=False + ) + assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix) + assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), submatrix) + assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement