From 9b77bb6e3783dd7afc4777e27cc0c2f4b6e6fc8f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 10 Jan 2022 17:31:42 +1100 Subject: [PATCH] New utility to get IFC all elements that are relevant in Brickschema --- src/ifcopenshell-python/ifcopenshell/util/brick.py | 14 +++++++++++++- src/ifcopenshell-python/test/util/test_brick.py | 11 +++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/brick.py b/src/ifcopenshell-python/ifcopenshell/util/brick.py index 0516abc737..174d30aa51 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/brick.py +++ b/src/ifcopenshell-python/ifcopenshell/util/brick.py @@ -17,4 +17,16 @@ def get_brick_type(element): result = ifc4_to_brick_map.get(f"{element.is_a()}.{predefined_type}", None) if not result: result = ifc4_to_brick_map.get(element.is_a(), None) - return result + if result: + return f"https://brickschema.org/schema/Brick#{result}" + + +def get_brick_elements(ifc_file): + classes = {c.split(".")[0] for c in ifc4_to_brick_map.keys()} + elements = [] + for ifc_class in classes: + try: + elements += ifc_file.by_type(ifc_class) + except: + pass + return elements diff --git a/src/ifcopenshell-python/test/util/test_brick.py b/src/ifcopenshell-python/test/util/test_brick.py index 5c4e8f010c..8f5f634da9 100644 --- a/src/ifcopenshell-python/test/util/test_brick.py +++ b/src/ifcopenshell-python/test/util/test_brick.py @@ -6,6 +6,13 @@ import ifcopenshell.util.brick as subject class TestGetBrickTypeIFC4(test.bootstrap.IFC4): def test_run(self): element = self.file.createIfcAirTerminalBox() - assert subject.get_brick_type(element) == "TerminalUnit" + assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#TerminalUnit" element.PredefinedType = "CONSTANTFLOW" - assert subject.get_brick_type(element) == "CAV" + assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#CAV" + + +class TestGetBrickElementsIFC4(test.bootstrap.IFC4): + def test_run(self): + element = self.file.createIfcAirTerminalBox() + self.file.createIfcWall() + assert subject.get_brick_elements(self.file) == [element]