From 9da4215bac90056ac7b223fb4c91e8582b493b38 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 19 Apr 2024 16:05:33 +0500 Subject: [PATCH] ifcopenshell.util.selector.filter_elements - inherited predefined types mentioned by @theoryshaw on osarch - https://community.osarch.org/discussion/comment/20126/#Comment_20126 --- src/ifcopenshell-python/ifcopenshell/util/selector.py | 5 ++++- src/ifcopenshell-python/test/util/test_selector.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index ee94fbc310..dd48eeb599 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -524,7 +524,10 @@ class FacetTransformer(lark.Transformer): name = name.children[0].value def filter_function(element): - element_value = getattr(element, name, None) + if name == "PredefinedType": + element_value = ifcopenshell.util.element.get_predefined_type(element) + else: + element_value = getattr(element, name, None) return self.compare(element_value, comparison, value) self.elements = set(filter(filter_function, self.elements)) diff --git a/src/ifcopenshell-python/test/util/test_selector.py b/src/ifcopenshell-python/test/util/test_selector.py index 571511d39f..78dbc7e946 100644 --- a/src/ifcopenshell-python/test/util/test_selector.py +++ b/src/ifcopenshell-python/test/util/test_selector.py @@ -165,6 +165,11 @@ class TestFilterElements(test.bootstrap.IFC4): element.Description = "Foobar" assert subject.filter_elements(self.file, "IfcWall, Name=Foo, Description=Foobar") == {element} + element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + element_type.PredefinedType = "SOLIDWALL" + ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type) + assert subject.filter_elements(self.file, "IfcWall, PredefinedType=SOLIDWALL") == {element} + def test_selecting_by_type(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")