From 2b27f4423f2bc9824c02fd5ddc322df74817cfb2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 22 Mar 2024 15:58:34 +0500 Subject: [PATCH] fix ui error getting active styles for non IfcMaterial materials Error was: ``` Traceback (most recent call last): File "\blenderbim\bim\module\material\ui.py", line 43, in draw MaterialsData.load() File "\blenderbim\bim\module\material\data.py", line 43, in load "active_styles": cls.active_styles(), ^^^^^^^^^^^^^^^^^^^ File "\blenderbim\bim\module\material\data.py", line 117, in active_styles return results File "\blenderbim\libs\site\packages\ifcopenshell\entity_instance.py", line 194, in __getattr__ raise AttributeError( AttributeError: entity instance of type 'IFC4.IfcMaterialLayerSet' has no attribute 'HasRepresentation' ``` --- .../blenderbim/bim/module/material/data.py | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/data.py b/src/blenderbim/blenderbim/bim/module/material/data.py index 4e984b93c9..8fdb424a8b 100644 --- a/src/blenderbim/blenderbim/bim/module/material/data.py +++ b/src/blenderbim/blenderbim/bim/module/material/data.py @@ -110,29 +110,38 @@ class MaterialsData: def active_styles(cls): props = bpy.context.scene.BIMMaterialProperties results = [] - if props.materials and props.active_material_index < len(props.materials): - material = props.materials[props.active_material_index].ifc_definition_id - if not material: - return results - material = tool.Ifc.get().by_id(material) - for definition in material.HasRepresentation: - for representation in definition.Representations: - if not representation.is_a("IfcStyledRepresentation"): + if not props.materials or props.active_material_index >= len(props.materials): + return results + + material = props.materials[props.active_material_index].ifc_definition_id + if not material: + return results + + material = tool.Ifc.get().by_id(material) + + if not material.is_a("IfcMaterial"): + return results + + for definition in material.HasRepresentation: + for representation in definition.Representations: + if not representation.is_a("IfcStyledRepresentation"): + continue + context = representation.ContextOfItems + for item in representation.Items: + if not item.is_a("IfcStyledItem"): continue - context = representation.ContextOfItems - for item in representation.Items: - if not item.is_a("IfcStyledItem"): - continue - for style in item.Styles: - if style.is_a("IfcSurfaceStyle"): - results.append({ + for style in item.Styles: + if style.is_a("IfcSurfaceStyle"): + results.append( + { "context_type": context.ContextType, "context_identifier": getattr(context, "ContextIdentifier", ""), "target_view": getattr(context, "TargetView", ""), "name": style.Name or "Unnamed", "id": style.id(), "context_id": context.id(), - }) + } + ) return results