From fafcd5dfca273ad8a058022b793e8433f5fe2d7e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 15 Aug 2023 10:35:36 +0500 Subject: [PATCH] root.copy_class to remove connections from previously connected ports --- .../ifcopenshell/api/root/copy_class.py | 1 + src/ifcopenshell-python/test/api/root/test_copy_class.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py index 061b695d24..9b8f78bf70 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -111,6 +111,7 @@ class Usecase: for port in new_ports: ifcopenshell.api.run("system.unassign_port", self.file, element=from_element, port=port) + ifcopenshell.api.run("system.disconnect_port", self.file, port=port) matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement) ifcopenshell.api.run( "geometry.edit_object_placement", diff --git a/src/ifcopenshell-python/test/api/root/test_copy_class.py b/src/ifcopenshell-python/test/api/root/test_copy_class.py index 782ef05472..520a074cde 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -201,11 +201,19 @@ class TestCopyClass(test.bootstrap.IFC4): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller") port = ifcopenshell.api.run("system.add_port", self.file) ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port) + + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller") + port2 = ifcopenshell.api.run("system.add_port", self.file) + ifcopenshell.api.run("system.assign_port", self.file, element=element2, port=port2) + ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="NOTDEFINED") + new = ifcopenshell.api.run("root.copy_class", self.file, product=element) new_ports = ifcopenshell.util.system.get_ports(new) assert port not in new_ports assert new_ports[0].is_a("IfcDistributionPort") assert ifcopenshell.util.system.get_ports(element) == [port] + # make sure port is disconnected from the previously connected ports + assert not ifcopenshell.util.system.get_connected_port(new_ports[0]) def test_not_copying_path_connections(self): element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")