mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
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.
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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 []:
|
||||
|
||||
Reference in New Issue
Block a user