From f8a82504292be2221a86930fee9bf0c0b5826236 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Mon, 17 Oct 2022 04:24:05 -0500 Subject: [PATCH] searching for an IfcMaterial in IfcMaterialDefinitions (#2503) * searching for an IfcMaterial in IfcMaterialDefinitions A start to trying to address: https://community.osarch.org/discussion/comment/13024/#Comment_13024 * refactored to a tighter version. Thanks Thomas. --- .../ifcopenshell/util/selector.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index f2dcac3e1a..8ac4f270be 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -188,7 +188,7 @@ class Selector: elif token_type == "NULL": value = None for element in elements: - element_value = cls.get_element_value(element, key) + element_value = cls.get_element_value(element, key, value) if element_value is None and value is not None and "not" not in comparison: continue if comparison and cls.filter_element(element, element_value, comparison, value): @@ -198,7 +198,7 @@ class Selector: return results @classmethod - def get_element_value(cls, element, key): + def get_element_value(cls, element, key, value): if "." in key and key.split(".")[0] == "type": try: element = ifcopenshell.util.element.get_type(element) @@ -209,12 +209,17 @@ class Selector: key = ".".join(key.split(".")[1:]) elif "." in key and key.split(".")[0] == "material": try: - element = ifcopenshell.util.element.get_material(element, should_skip_usage=True) - if not element: + material_definition = ifcopenshell.util.element.get_material(element, should_skip_usage=True) + key = ".".join(key.split(".")[1:]) + materials = [inst for inst in cls.file.traverse(material_definition) if inst.is_a('IfcMaterial')] + for material in materials: + info = material.get_info() + if key in info and info[key] == value: + element = material + if not material_definition: return None except: return - key = ".".join(key.split(".")[1:]) elif "." in key and key.split(".")[0] == "container": try: element = ifcopenshell.util.element.get_container(element)