From f859f11addde062ac09da14d04cefd7dde303e97 Mon Sep 17 00:00:00 2001 From: Chun <36185113+chunchk@users.noreply.github.com> Date: Tue, 14 Mar 2023 14:49:30 +0800 Subject: [PATCH] Update functions of get_connected_to and get_connected_from compatible with IFC4 and IFC2X3 --- .../ifcopenshell/util/system.py | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/system.py b/src/ifcopenshell-python/ifcopenshell/util/system.py index 2f24fb2a58..e584bc5c7c 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/system.py +++ b/src/ifcopenshell-python/ifcopenshell/util/system.py @@ -83,17 +83,31 @@ def get_connected_port(port): def get_connected_to(element): + from blenderbim.bim.ifc import IfcStore + ifcSchema = IfcStore.get_file().schema results = [] - for port in ifcopenshell.util.system.get_ports(element): - for relConnectsPort in port.ConnectedTo: - for relNest in relConnectsPort.RelatedPort.Nests: - results.extend(relNest.RelatingObject) + if ifcSchema == "IFC4": + for port in ifcopenshell.util.system.get_ports(element): + for relConnectsPort in port.ConnectedTo: + for relNest in relConnectsPort.RelatedPort.Nests: + results.extend(relNest.RelatingObject) + elif ifcSchema == "IFC2X3": + for port in element.HasPorts: + for relConnectsPort in port.RelatingPort.ConnectedTo: + results.extend([r.RelatedElement for r in relConnectsPort.RelatedPort.ContainedIn if r.RelatedElement != element]) return results def get_connected_from(element): + from blenderbim.bim.ifc import IfcStore + ifcSchema = IfcStore.get_file().schema results = [] - for port in ifcopenshell.util.system.get_ports(element): - for relConnectsPort in port.ConnectedFrom: - for relNest in relConnectsPort.RelatingPort.Nests: - results.extend(relNest.RelatingObject) + if ifcSchema == "IFC4": + for port in ifcopenshell.util.system.get_ports(element): + for relConnectsPort in port.ConnectedFrom: + for relNest in relConnectsPort.RelatedPort.Nests: + results.extend(relNest.RelatingObject) + elif ifcSchema == "IFC2X3": + for rel in element.HasPorts: + for rel2 in rel.RelatingPort.ConnectedFrom: + results.extend([r.RelatedElement for r in rel2.RelatingPort.ContainedIn if r.RelatedElement != element]) return results \ No newline at end of file