From 298869616125e6acbd3b74674092fa8ac687ee72 Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Sun, 12 Jul 2026 08:29:56 +0300 Subject: [PATCH] Bonsai: keep "disable selection" objects visible when activating a drawing (#7681) tool.Blender.isolate_objects keeps objects visible by selecting the intended set and then hiding everything unselected via hide_view_set(unselected=True). Blender refuses to select an object whose "disable selection" (hide_select) is enabled, so such an object is treated as unselected and hidden. Activating a drawing therefore turned off any object that had disable-selection on. Temporarily clear hide_select on the target objects so they can be selected (and thus kept visible), then restore it. The clear/restore is wrapped in try/finally so hide_select is always restored even if the hide operator raises. Verified in headless Blender with real objects: an object with hide_select set is hidden by the pre-fix logic and stays visible with the fix, hide_select is preserved, and unrelated objects are still hidden. Generated with the assistance of an AI coding tool. Co-Authored-By: Claude Opus 4.8 --- src/bonsai/bonsai/tool/blender.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index aa9656c76e..d05b6d7058 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -2315,10 +2315,23 @@ class Blender(bonsai.core.tool.Blender): bpy.ops.object.hide_view_clear(select=False) bpy.ops.object.select_all(action="DESELECT") - for obj in objs: - obj.select_set(True) - with bpy.context.temp_override(**override): - bpy.ops.object.hide_view_set(unselected=True) + # Objects with "disable selection" (hide_select) enabled cannot be + # selected, so they would be treated as unselected and hidden by + # hide_view_set(unselected=True) below - see #7681. Temporarily clear + # hide_select so they can be selected (and thus kept visible), then + # restore it afterwards. + unselectable = [] + try: + for obj in objs: + if obj.hide_select: + obj.hide_select = False + unselectable.append(obj) + obj.select_set(True) + with bpy.context.temp_override(**override): + bpy.ops.object.hide_view_set(unselected=True) + finally: + for obj in unselectable: + obj.hide_select = True bpy.ops.object.select_all(action="DESELECT") for name in previously_selected: