From bda9dfd4cc9a7c576dbe04eb6755301003474863 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 31 May 2024 12:04:02 +0500 Subject: [PATCH] materials ui - avoid having multiple "Uncategorised" categories Previously it would create multiple same named "Uncategorised" categories for each case when Category was "", None, "Uncategorised", which was confusing and some of them ("" and None) would expand simultaneously when you would try to expand one. Removed `or "Uncategorised"` from ui.py as there shouldn't be a need for this since all cases are handled when items are added. --- src/blenderbim/blenderbim/bim/module/material/ui.py | 2 +- src/blenderbim/blenderbim/tool/material.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/ui.py b/src/blenderbim/blenderbim/bim/module/material/ui.py index e9f369b65c..17ff769851 100644 --- a/src/blenderbim/blenderbim/bim/module/material/ui.py +++ b/src/blenderbim/blenderbim/bim/module/material/ui.py @@ -343,7 +343,7 @@ class BIM_UL_materials(UIList): row.operator( "bim.expand_material_category", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT" ).category = item.name - row.label(text=item.name or "Uncategorised") + row.label(text=item.name) else: row.label(text="", icon="BLANK1") row.label(text=item.name, icon="MATERIAL") diff --git a/src/blenderbim/blenderbim/tool/material.py b/src/blenderbim/blenderbim/tool/material.py index 4a72301f2f..6dbb345311 100644 --- a/src/blenderbim/blenderbim/tool/material.py +++ b/src/blenderbim/blenderbim/tool/material.py @@ -24,6 +24,7 @@ import blenderbim.tool as tool import blenderbim.bim.helper import ifcopenshell.util.unit import ifcopenshell.util.element +from collections import defaultdict from typing import Union, Any @@ -67,12 +68,16 @@ class Material(blenderbim.core.tool.Material): elif material_type == "IfcMaterialList": get_name = lambda x: "Unnamed" materials = sorted(tool.Ifc.get().by_type(material_type), key=get_name) - categories = {} + categories = defaultdict(list) if material_type == "IfcMaterial": - [categories.setdefault(getattr(m, "Category", "Uncategorised"), []).append(m) for m in materials] + for m in materials: + # IfcMaterial has Category since IFC4. + category = getattr(m, "Category", None) + category = category or "Uncategorised" + categories[category].append(m) for category, mats in categories.items(): cat = props.materials.add() - cat.name = category or "" + cat.name = category cat.is_category = True cat.is_expanded = cat.name in expanded_categories for material in mats if cat.is_expanded else []: