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
This commit is contained in:
Andrej
2025-05-30 16:58:54 +05:00
parent c7b4033f6f
commit cc60794293
2 changed files with 13 additions and 4 deletions
@@ -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)
@@ -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]]]: