diff --git a/src/ifcblenderexport/blenderbim/bim/cut_ifc.py b/src/ifcblenderexport/blenderbim/bim/cut_ifc.py index f7e86f81bc..bfb138b8ac 100644 --- a/src/ifcblenderexport/blenderbim/bim/cut_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/cut_ifc.py @@ -771,13 +771,13 @@ class IfcCutter: def get_classes(self, element, position): classes = [position, element.is_a()] - for association in element.HasAssociations: - if association.is_a("IfcRelAssociatesMaterial"): - classes.append( - "material-{}".format( - re.sub("[^0-9a-zA-Z]+", "", self.get_material_name(association.RelatingMaterial)) - ) + material = ifcopenshell.util.element.get_material(element) + if material: + classes.append( + "material-{}".format( + re.sub("[^0-9a-zA-Z]+", "", self.get_material_name(material)) ) + ) classes.append("globalid-{}".format(element.GlobalId)) for attribute in self.attributes: result = self.selector.get_element_value(element, attribute) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 68d03c227a..65cc386e59 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -67,11 +67,19 @@ def get_material(element): if hasattr(element, "HasAssociations") and element.HasAssociations: for relationship in element.HasAssociations: if relationship.is_a("IfcRelAssociatesMaterial"): + if relationship.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"): + return relationship.RelatingMaterial.ForLayerSet + elif relationship.RelatingMaterial.is_a("IfcMaterialProfileSetUsage"): + return relationship.RelatingMaterial.ForProfileSet 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"): + if relationship.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"): + return relationship.RelatingMaterial.ForLayerSet + elif relationship.RelatingMaterial.is_a("IfcMaterialProfileSetUsage"): + return relationship.RelatingMaterial.ForProfileSet return relationship.RelatingMaterial