mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
bim.search - fix error when unselectable objects get in the way #7635
This commit is contained in:
@@ -788,11 +788,10 @@ class Search(Operator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
objs = [obj for e in results if isinstance(obj := tool.Ifc.get_object(e), bpy.types.Object)]
|
objs = [obj for e in results if isinstance(obj := tool.Ifc.get_object(e), bpy.types.Object)]
|
||||||
for obj in objs:
|
active_object = next(iter(objs), None)
|
||||||
tool.Blender.set_object_selection(obj)
|
selection = tool.Blender.validate_object_selection(context, active_object, objs)
|
||||||
if objs:
|
tool.Blender.set_objects_selection(*selection, clear_previous_selection=False)
|
||||||
tool.Blender.set_active_object(objs[0])
|
self.report({"INFO"}, f"{len(results)} Results, {len(selection.selected_objects)} Objects Selected")
|
||||||
self.report({"INFO"}, f"{len(results)} Results.")
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ from typing import (
|
|||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Literal,
|
Literal,
|
||||||
|
NamedTuple,
|
||||||
Optional,
|
Optional,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
Union,
|
Union,
|
||||||
@@ -718,13 +719,18 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
if active_object:
|
if active_object:
|
||||||
active_object.select_set(True)
|
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
|
@classmethod
|
||||||
def validate_object_selection(
|
def validate_object_selection(
|
||||||
cls,
|
cls,
|
||||||
context: bpy.types.Context,
|
context: bpy.types.Context,
|
||||||
active_object: Union[bpy.types.Object, None] = None,
|
active_object: Union[bpy.types.Object, None] = None,
|
||||||
selected_objects: Sequence[bpy.types.Object] = (),
|
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.
|
"""Validate object selection and return only valid objects.
|
||||||
|
|
||||||
Can be used before ``set_objects_selection`` to avoid errors
|
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):
|
if active_object and not cls.is_valid_data_block(active_object):
|
||||||
active_object = None
|
active_object = None
|
||||||
|
|
||||||
return context, active_object, new_selected_objects
|
return cls.ObjectsSelectionArgs(context, active_object, new_selected_objects)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_objects_selection(cls) -> None:
|
def clear_objects_selection(cls) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user