From cf348fffe1f402ac1ba4e2aaa50d0110b45f5761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justus=20Bl=C3=B6nnigen?= Date: Thu, 28 Nov 2024 15:00:54 +0100 Subject: [PATCH 1/2] Return to global view before closing a window Blender currently is not clearing the localview when closing a window. (Known bug: https://projects.blender.org/blender/blender/issues/104069) --- client/ayon_blender/api/capture.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/ayon_blender/api/capture.py b/client/ayon_blender/api/capture.py index e5e6041..7b153cd 100644 --- a/client/ayon_blender/api/capture.py +++ b/client/ayon_blender/api/capture.py @@ -101,6 +101,8 @@ def capture( view_context=True ) + restore_global_view(window) + return filename @@ -117,7 +119,6 @@ def capture( }, } - def isolate_objects(window, objects): """Isolate selection""" deselect_all() @@ -133,7 +134,22 @@ def isolate_objects(window, objects): deselect_all() +def restore_global_view(window, isolate=None): + """Exit local view if active. + Blender currently does not exit localview when closing windows. + """ + + types = {"MESH", "GPENCIL"} + objects = [obj for obj in window.scene.objects if obj.type in types] + + context = create_blender_context(selected=isolate or objects, window=window) + + with bpy.context.temp_override(**context): + # Only toggle back if in local view + if bpy.context.space_data.local_view: + bpy.ops.view3d.localview() + def _apply_options(entity, options): for option, value in options.items(): if isinstance(value, dict): From 740a153caccd1943a65c8560bfea5cd13bee8dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justus=20Bl=C3=B6nnigen?= Date: Thu, 28 Nov 2024 17:09:45 +0100 Subject: [PATCH 2/2] Update capture.py Removed isolate behaviour Moved restore_global_view() into _independent_window() --- client/ayon_blender/api/capture.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/ayon_blender/api/capture.py b/client/ayon_blender/api/capture.py index 7b153cd..3482934 100644 --- a/client/ayon_blender/api/capture.py +++ b/client/ayon_blender/api/capture.py @@ -101,8 +101,6 @@ def capture( view_context=True ) - restore_global_view(window) - return filename @@ -134,7 +132,7 @@ def isolate_objects(window, objects): deselect_all() -def restore_global_view(window, isolate=None): +def restore_global_view(window): """Exit local view if active. Blender currently does not exit localview when closing windows. @@ -143,7 +141,7 @@ def restore_global_view(window, isolate=None): types = {"MESH", "GPENCIL"} objects = [obj for obj in window.scene.objects if obj.type in types] - context = create_blender_context(selected=isolate or objects, window=window) + context = create_blender_context(selected=objects, window=window) with bpy.context.temp_override(**context): # Only toggle back if in local view @@ -295,4 +293,6 @@ def _independent_window(): try: yield window finally: + restore_global_view(window) bpy.ops.wm.window_close() +