From cc607942933d108cd8f91be81f6d61d5a397ad06 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 30 May 2025 16:58:54 +0500 Subject: [PATCH] edit style for rep item - fallback in case user has no styles #6764 Or if style was removed in the process of editing. And it seems now UI will never appear broken that way. Previously - https://files.catbox.moe/exhkln.png Currently - https://files.catbox.moe/r36be8.png --- src/bonsai/bonsai/bim/module/geometry/operator.py | 13 ++++++++++--- src/bonsai/bonsai/bim/module/material/data.py | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 28de1f78af..9a883c0718 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -2558,7 +2558,8 @@ class EnableEditingRepresentationItemStyle(bpy.types.Operator, tool.Ifc.Operator ifc_file = tool.Ifc.get() # set dropdown to currently active style - representation_item_id = props.active_item.ifc_definition_id + assert (active_item := props.active_item) + representation_item_id = active_item.ifc_definition_id representation_item = ifc_file.by_id(representation_item_id) style = tool.Style.get_representation_item_style(representation_item) if style: @@ -2577,8 +2578,14 @@ class EditRepresentationItemStyle(bpy.types.Operator, tool.Ifc.Operator): props.is_editing_item_style = False ifc_file = tool.Ifc.get() - surface_style = ifc_file.by_id(int(props.representation_item_style)) - representation_item_id = props.active_item.ifc_definition_id + surface_style_id = tool.Blender.get_enum_safe(props, "representation_item_style") + if surface_style_id in (None, "-"): + surface_style = None + else: + surface_style = ifc_file.by_id(int(props.representation_item_style)) + + assert (active_item := props.active_item) + representation_item_id = active_item.ifc_definition_id representation_item = ifc_file.by_id(representation_item_id) tool.Style.assign_style_to_representation_item(representation_item, surface_style) diff --git a/src/bonsai/bonsai/bim/module/material/data.py b/src/bonsai/bonsai/bim/module/material/data.py index 222677b6c2..ccd04e164d 100644 --- a/src/bonsai/bonsai/bim/module/material/data.py +++ b/src/bonsai/bonsai/bim/module/material/data.py @@ -101,7 +101,9 @@ class MaterialsData: for s in tool.Ifc.get().by_type("IfcPresentationStyle") if (style_name := s.Name) is not None ] - return natsorted(results, key=lambda i: i[1]) + results = natsorted(results, key=lambda i: i[1]) + results.insert(0, ("-", "No Surface Style", "")) + return results @classmethod def material_styles_data(cls) -> dict[int, list[dict[str, Any]]]: