From c9b0a7c3dedc01b02abd6d7c5f79fb7255d09647 Mon Sep 17 00:00:00 2001 From: Sigma Dimensions <79010126+myoualid@users.noreply.github.com> Date: Fri, 20 Jan 2023 21:23:40 +0100 Subject: [PATCH] Attempt to fix selector bug where retrieving material values gets caught in exception --- .../ifcopenshell/util/selector.py | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 4c6837cc5c..892a0673b1 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -212,15 +212,26 @@ class Selector: key = ".".join(key.split(".")[1:]) elif "." in key and key.split(".")[0] == "material": try: - 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 + material_definition = ifcopenshell.util.element.get_material( + element, should_skip_usage=True + ) if not material_definition: return None + key = ".".join(key.split(".")[1:]) + if value: + materials = [ + inst + for inst in cls.file.traverse(material_definition) + if inst.is_a("IfcMaterial") + ] + for material in materials or []: + info = material.get_info() + if key in info and info[key] == value: + element = material + if material_definition.is_a("IfcMaterialLayerSet"): + info = material_definition.get_info() + if key in info: + return info[key] except: return elif "." in key and key.split(".")[0] == "container":