bim.search - fix error when unselectable objects get in the way #7635

This commit is contained in:
Andrej730
2026-02-04 19:46:35 +05:00
parent 2f586d6b9e
commit 7411da2ae8
2 changed files with 12 additions and 7 deletions
@@ -788,11 +788,10 @@ class Search(Operator):
)
objs = [obj for e in results if isinstance(obj := tool.Ifc.get_object(e), bpy.types.Object)]
for obj in objs:
tool.Blender.set_object_selection(obj)
if objs:
tool.Blender.set_active_object(objs[0])
self.report({"INFO"}, f"{len(results)} Results.")
active_object = next(iter(objs), None)
selection = tool.Blender.validate_object_selection(context, active_object, objs)
tool.Blender.set_objects_selection(*selection, clear_previous_selection=False)
self.report({"INFO"}, f"{len(results)} Results, {len(selection.selected_objects)} Objects Selected")
return {"FINISHED"}
+8 -2
View File
@@ -36,6 +36,7 @@ from typing import (
TYPE_CHECKING,
Any,
Literal,
NamedTuple,
Optional,
TypeVar,
Union,
@@ -718,13 +719,18 @@ class Blender(bonsai.core.tool.Blender):
if active_object:
active_object.select_set(True)
class ObjectsSelectionArgs(NamedTuple):
context: bpy.types.Context
active_object: bpy.types.Object | None
selected_objects: list[bpy.types.Object]
@classmethod
def validate_object_selection(
cls,
context: bpy.types.Context,
active_object: Union[bpy.types.Object, None] = None,
selected_objects: Sequence[bpy.types.Object] = (),
) -> tuple[bpy.types.Context, Union[bpy.types.Object, None], list[bpy.types.Object]]:
) -> ObjectsSelectionArgs:
"""Validate object selection and return only valid objects.
Can be used before ``set_objects_selection`` to avoid errors
@@ -739,7 +745,7 @@ class Blender(bonsai.core.tool.Blender):
if active_object and not cls.is_valid_data_block(active_object):
active_object = None
return context, active_object, new_selected_objects
return cls.ObjectsSelectionArgs(context, active_object, new_selected_objects)
@classmethod
def clear_objects_selection(cls) -> None: