Add operator to run search generic search queries

So it will be easy to add queries to quick favorites.
This commit is contained in:
Andrej730
2026-03-11 15:32:33 +05:00
parent 97f900e62f
commit 61ba6a7989
3 changed files with 29 additions and 1 deletions
@@ -489,7 +489,11 @@ class AddQuickFavoritesItem(bpy.types.Operator):
def execute(self, context) -> set["rna_enums.OperatorReturnItems"]:
props = tool.Misc.get_misc_props()
props.quick_favorites.add()
fav = props.quick_favorites.add()
fav.search = "bim.select_query_elements"
index = len(props.quick_favorites) - 1
bpy.ops.bim.confirm_quick_favorite_operator(index=index)
fav.properties["query"].string_value = "IfcWall"
return {"FINISHED"}
@@ -41,6 +41,7 @@ classes = (
operator.SelectByProperty,
operator.SelectFilterElements,
operator.SelectGlobalId,
operator.SelectQueryElements,
operator.SelectIfcClass,
operator.SelectSimilar,
operator.ShowAllElements,
@@ -42,6 +42,8 @@ from bonsai.bim.ifc import IfcStore
from bonsai.bim.prop import StrProperty
if TYPE_CHECKING:
from bpy.stub_internal import rna_enums
from bonsai.bim.prop import BIMFacet
@@ -791,6 +793,27 @@ class Search(Operator):
return {"FINISHED"}
class SelectQueryElements(Operator):
bl_idname = "bim.select_query_elements"
bl_label = "Select Query Elements"
bl_description = "Select elements matching an provided selector query"
bl_options = {"REGISTER", "UNDO"}
query: StringProperty(name="Query") # pyright: ignore[reportRedeclaration]
if TYPE_CHECKING:
query: str
def execute(self, context) -> set["rna_enums.OperatorReturnItems"]:
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), self.query)
objs = [obj for e in results if isinstance(obj := tool.Ifc.get_object(e), bpy.types.Object)]
active_object = context.active_object or 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"}
class SaveSearch(Operator, tool.Ifc.Operator):
bl_idname = "bim.save_search"
bl_label = "Save Search"