mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
bim.search - set found object as active
As sometimes it's hard of find a selected object in outliner if it's not active.
This commit is contained in:
@@ -40,6 +40,7 @@ from bpy.props import (
|
|||||||
CollectionProperty,
|
CollectionProperty,
|
||||||
)
|
)
|
||||||
from typing import TYPE_CHECKING, Literal, get_args
|
from typing import TYPE_CHECKING, Literal, get_args
|
||||||
|
from typing_extensions import assert_never
|
||||||
|
|
||||||
|
|
||||||
class AddFilterGroup(Operator):
|
class AddFilterGroup(Operator):
|
||||||
@@ -144,6 +145,7 @@ class EditFilterQuery(Operator, tool.Ifc.Operator):
|
|||||||
class Search(Operator):
|
class Search(Operator):
|
||||||
bl_idname = "bim.search"
|
bl_idname = "bim.search"
|
||||||
bl_label = "Search"
|
bl_label = "Search"
|
||||||
|
bl_description = "Search IFC elements by the provided query and add them to the current selection."
|
||||||
|
|
||||||
PropertyGroupType = Literal["CsvProperties", "BIMSearchProperties"]
|
PropertyGroupType = Literal["CsvProperties", "BIMSearchProperties"]
|
||||||
property_group: bpy.props.EnumProperty(
|
property_group: bpy.props.EnumProperty(
|
||||||
@@ -159,17 +161,18 @@ class Search(Operator):
|
|||||||
elif self.property_group == "BIMSearchProperties":
|
elif self.property_group == "BIMSearchProperties":
|
||||||
props = tool.Search.get_search_props()
|
props = tool.Search.get_search_props()
|
||||||
else:
|
else:
|
||||||
raise Exception(f"bim.search - unexpected property group name '{self.property_group}'.")
|
assert_never(self.property_group)
|
||||||
|
|
||||||
results = ifcopenshell.util.selector.filter_elements(
|
results = ifcopenshell.util.selector.filter_elements(
|
||||||
tool.Ifc.get(), tool.Search.export_filter_query(props.filter_groups)
|
tool.Ifc.get(), tool.Search.export_filter_query(props.filter_groups)
|
||||||
)
|
)
|
||||||
|
|
||||||
total_selected = 0
|
objs = [obj for e in results if isinstance(obj := tool.Ifc.get_object(e), bpy.types.Object)]
|
||||||
for element in results:
|
for obj in objs:
|
||||||
if obj := tool.Ifc.get_object(element):
|
tool.Blender.set_object_selection(obj)
|
||||||
obj.select_set(True)
|
if objs:
|
||||||
self.report({"INFO"}, f"{len(results)} Results")
|
tool.Blender.set_active_object(objs[0])
|
||||||
|
self.report({"INFO"}, f"{len(results)} Results.")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -114,11 +114,13 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_active_object(cls, obj: bpy.types.Object) -> None:
|
def set_active_object(cls, obj: bpy.types.Object) -> None:
|
||||||
|
"""Set active object and select it."""
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
obj.select_set(True)
|
obj.select_set(True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_active_object(cls) -> None:
|
def clear_active_object(cls) -> None:
|
||||||
|
"""Clear active object, object is not unselected."""
|
||||||
bpy.context.view_layer.objects.active = None
|
bpy.context.view_layer.objects.active = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user