From c70b41f21a671812bc48dc815873385379433bc5 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 2 Dec 2020 09:03:18 +1100 Subject: [PATCH] Fix #1112. You can now tag material attributes. --- src/ifcopenshell-python/ifcopenshell/util/element.py | 12 ++++++++++++ .../ifcopenshell/util/selector.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 87d5991646..68d03c227a 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -63,6 +63,18 @@ def get_type(element): return relationship.RelatingType +def get_material(element): + if hasattr(element, "HasAssociations") and element.HasAssociations: + for relationship in element.HasAssociations: + if relationship.is_a("IfcRelAssociatesMaterial"): + return relationship.RelatingMaterial + relating_type = get_type(element) + if hasattr(relating_type, "HasAssociations") and relating_type.HasAssociations: + for relationship in relating_type.HasAssociations: + if relationship.is_a("IfcRelAssociatesMaterial"): + return relationship.RelatingMaterial + + def replace_attribute(element, old, new): for i, attribute in enumerate(element): if attribute == old: diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 29a5b75077..b42b7fd69f 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -219,6 +219,14 @@ class Selector: except: return key = ".".join(key.split(".")[1:]) + elif "." in key and key.split(".")[0] == "material": + try: + element = ifcopenshell.util.element.get_material(element) + if not element: + return None + except: + return + key = ".".join(key.split(".")[1:]) info = element.get_info() if key in info: return info[key]