From a7a28f613b6075e11114673936eb197bd30077be Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 29 Jul 2024 17:38:06 +0500 Subject: [PATCH] Fix errors in tests and scripts removing styles remove_style relies on style_type which is using StylesData to get the enum of it's values and StylesData will fail to load on `material = tool.Ifc.get_object(ifc_file.by_id(style.ifc_definition_id))` as ifc_definition_id was removed but not yet removed as an item from styles ui. This issue doesn't occur when user is working from UI since StylesData precached when they load styles UI but if they run a script (as we do in bim tests) StylesData is not precached and will be loaded when get_active_style_type() is called leading to errors. --- src/blenderbim/blenderbim/core/style.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/core/style.py b/src/blenderbim/blenderbim/core/style.py index 47f76b378d..b98c749c42 100644 --- a/src/blenderbim/blenderbim/core/style.py +++ b/src/blenderbim/blenderbim/core/style.py @@ -57,11 +57,14 @@ def update_external_style( def remove_style(ifc: tool.Ifc, style_tool: tool.Style, style: ifcopenshell.entity_instance) -> None: obj = ifc.get_object(style) + # Get style_type before removing object as later StylesData might fail to load + # due object not yet removed completely. + style_type = style_tool.get_active_style_type() ifc.unlink(element=style) ifc.run("style.remove_style", style=style) style_tool.delete_object(obj) if style_tool.is_editing_styles(): - style_tool.import_presentation_styles(style_tool.get_active_style_type()) + style_tool.import_presentation_styles(style_type) def update_style_colours(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Material, verbose: bool = False) -> None: