Fix #2107. Materials and styles in the scene manager are now shown alphabetically

This commit is contained in:
Dion Moult
2022-05-01 12:01:24 +10:00
parent f54a5cf6e0
commit 9577c40386
2 changed files with 10 additions and 8 deletions
+8 -7
View File
@@ -56,15 +56,16 @@ class Material(blenderbim.core.tool.Material):
def import_material_definitions(cls, material_type):
props = bpy.context.scene.BIMMaterialProperties
props.materials.clear()
for material in tool.Ifc.get().by_type(material_type):
get_name = lambda x: x.Name or "Unnamed"
if material_type == "IfcMaterialLayerSet":
get_name = lambda x: x.LayerSetName or "Unnamed"
elif material_type == "IfcMaterialList":
get_name = lambda x: "Unnamed"
materials = sorted(tool.Ifc.get().by_type(material_type), key=get_name)
for material in materials:
new = props.materials.add()
new.ifc_definition_id = material.id()
if material.is_a("IfcMaterialLayerSet"):
new.name = material.LayerSetName or "Unnamed"
elif material.is_a("IfcMaterialList"):
new.name = "Unnamed"
else:
new.name = material.Name or "Unnamed"
new.name = get_name(material)
new.total_elements = len(set(ifcopenshell.util.element.get_elements_by_material(tool.Ifc.get(), material)))
@classmethod
+2 -1
View File
@@ -183,7 +183,8 @@ class Style(blenderbim.core.tool.Style):
def import_presentation_styles(cls, style_type):
props = bpy.context.scene.BIMStylesProperties
props.styles.clear()
for style in tool.Ifc.get().by_type(style_type):
styles = sorted(tool.Ifc.get().by_type(style_type), key=lambda x: x.Name or "Unnamed")
for style in styles:
new = props.styles.add()
new.ifc_definition_id = style.id()
new.name = style.Name or "Unnamed"