mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 17:16:24 +00:00
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:
@@ -188,7 +188,7 @@ class Selector:
|
|||||||
elif token_type == "NULL":
|
elif token_type == "NULL":
|
||||||
value = None
|
value = None
|
||||||
for element in elements:
|
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:
|
if element_value is None and value is not None and "not" not in comparison:
|
||||||
continue
|
continue
|
||||||
if comparison and cls.filter_element(element, element_value, comparison, value):
|
if comparison and cls.filter_element(element, element_value, comparison, value):
|
||||||
@@ -198,7 +198,7 @@ class Selector:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_element_value(cls, element, key):
|
def get_element_value(cls, element, key, value):
|
||||||
if "." in key and key.split(".")[0] == "type":
|
if "." in key and key.split(".")[0] == "type":
|
||||||
try:
|
try:
|
||||||
element = ifcopenshell.util.element.get_type(element)
|
element = ifcopenshell.util.element.get_type(element)
|
||||||
@@ -209,12 +209,17 @@ class Selector:
|
|||||||
key = ".".join(key.split(".")[1:])
|
key = ".".join(key.split(".")[1:])
|
||||||
elif "." in key and key.split(".")[0] == "material":
|
elif "." in key and key.split(".")[0] == "material":
|
||||||
try:
|
try:
|
||||||
element = ifcopenshell.util.element.get_material(element, should_skip_usage=True)
|
material_definition = ifcopenshell.util.element.get_material(element, should_skip_usage=True)
|
||||||
if not element:
|
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
|
return None
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
key = ".".join(key.split(".")[1:])
|
|
||||||
elif "." in key and key.split(".")[0] == "container":
|
elif "." in key and key.split(".")[0] == "container":
|
||||||
try:
|
try:
|
||||||
element = ifcopenshell.util.element.get_container(element)
|
element = ifcopenshell.util.element.get_container(element)
|
||||||
|
|||||||
Reference in New Issue
Block a user