mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 18:12:28 +00:00
Bonsai: skip out-of-view-layer spaces in toggle_hide_spaces (#5309)
Toggling space visibility crashed with `RuntimeError: Object 'IfcSpace/...' cannot be hidden because it is not in View Layer 'ViewLayer'!` when a space object lived in a collection excluded from the active view layer. tool.Spatial.toggle_hide_spaces called hide_get/hide_set unconditionally; Blender raises for any object not in the active view layer. The rest of spatial.py already guards these calls via view_layer.objects.get(obj.name); this method was the outlier. Filter the spaces to objects present in the active view layer, derive the toggle direction from the first surviving object, and apply hide_set only to those. Objects not in the view layer are skipped (they cannot be hidden anyway). Also returns cleanly when nothing is toggleable. Verified live in headless Blender: with one space in an excluded collection, the old code raised the reported RuntimeError; the fix completes, hides the in-view-layer space, and skips the excluded one. Core test_spatial.py: 12 passed. Generated with the assistance of an AI coding tool. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1258,19 +1258,20 @@ class Spatial(bonsai.core.tool.Spatial):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def toggle_hide_spaces(cls, spaces: list[ifcopenshell.entity_instance]) -> None:
|
def toggle_hide_spaces(cls, spaces: list[ifcopenshell.entity_instance]) -> None:
|
||||||
first_obj = tool.Ifc.get_object(spaces[0])
|
# `hide_get`/`hide_set` raise for objects that are not in the active view
|
||||||
assert isinstance(first_obj, bpy.types.Object)
|
# layer (e.g. spaces living in an excluded collection), so skip those.
|
||||||
obj: bpy.types.Object
|
view_layer = bpy.context.view_layer
|
||||||
if first_obj.hide_get() == False:
|
objs = [
|
||||||
for space in spaces:
|
obj
|
||||||
obj = tool.Ifc.get_object(space)
|
for space in spaces
|
||||||
obj.hide_set(True)
|
if isinstance(obj := tool.Ifc.get_object(space), bpy.types.Object) and view_layer.objects.get(obj.name)
|
||||||
|
]
|
||||||
|
if not objs:
|
||||||
return
|
return
|
||||||
|
|
||||||
elif first_obj.hide_get() == True:
|
should_hide = objs[0].hide_get() == False
|
||||||
for space in spaces:
|
for obj in objs:
|
||||||
obj = tool.Ifc.get_object(space)
|
obj.hide_set(should_hide)
|
||||||
obj.hide_set(False)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_default_container(cls, container: ifcopenshell.entity_instance) -> None:
|
def set_default_container(cls, container: ifcopenshell.entity_instance) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user