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.
This commit is contained in:
Ryan Schultz
2022-10-17 04:24:05 -05:00
committed by GitHub
parent a75341b36e
commit f8a8250429
@@ -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)