New utility function for getting ports of an element

This commit is contained in:
Dion Moult
2022-01-24 16:16:08 +11:00
parent e38759c39d
commit 8569bcf350
2 changed files with 25 additions and 0 deletions
@@ -34,3 +34,12 @@ def get_element_systems(element):
]:
results.append(rel.RelatingGroup)
return results
def get_ports(element):
results = []
for rel in getattr(element, "IsNestedBy", []) or []:
results.extend([o for o in rel.RelatedObjects if o.is_a("IfcDistributionPort")])
for rel in element.HasPorts or []:
results.append(rel.RelatingPort)
return results
@@ -45,3 +45,19 @@ class TestGetElementSystems(test.bootstrap.IFC4):
"system.assign_system", self.file, product=element, system=self.file.createIfcStructuralAnalysisModel()
)
assert not subject.get_element_systems(element)
class TestGetPorts(test.bootstrap.IFC4):
def test_run(self):
port = self.file.createIfcDistributionPort()
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
assert subject.get_ports(element) == [port]
class TestGetPortsIFC2X3(test.bootstrap.IFC2X3):
def test_run(self):
port = self.file.createIfcDistributionPort()
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
assert subject.get_ports(element) == [port]