From 4e1d0bcf2221c99ce321c6776d764e3923a6da89 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 4 Nov 2025 17:06:08 +0500 Subject: [PATCH] Fix failing selecting products tests (3aa5ddb07) After 3aa5ddb07 `select_products` adds to current selection, instead of resetting it. So couple tests started to fail since they create new objects and `view_layer` is not yet updated (previously `bpy.ops.object.select_all(action="DESELECT")` was also implicitly updating view layer). ``` FAILED test/tool/test_spatial.py::TestSelectProducts::test_select_products - AssertionError: assert bpy.data.objects['Object'] in [] FAILED test/tool/test_system.py::TestSelectSystemProducts::test_run - AssertionError: assert bpy.data.objects['Object'] in [] ``` --- src/bonsai/bonsai/tool/spatial.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/tool/spatial.py b/src/bonsai/bonsai/tool/spatial.py index ec0835b0a9..454d6b5b32 100644 --- a/src/bonsai/bonsai/tool/spatial.py +++ b/src/bonsai/bonsai/tool/spatial.py @@ -175,9 +175,12 @@ class Spatial(bonsai.core.tool.Spatial): @classmethod def select_products(cls, products: Iterable[ifcopenshell.entity_instance], unhide: bool = False) -> None: + assert (view_layer := bpy.context.view_layer) + # Update view layer, otherwise `objects` might be missing just created objects. + view_layer.update() for product in products: obj = tool.Ifc.get_object(product) - if obj and bpy.context.view_layer.objects.get(obj.name): + if obj and view_layer.objects.get(obj.name): if unhide: obj.hide_set(False) obj.select_set(True)