mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 00:03:17 +00:00
Add operator to run search generic search queries
So it will be easy to add queries to quick favorites.
This commit is contained in:
@@ -489,7 +489,11 @@ class AddQuickFavoritesItem(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context) -> set["rna_enums.OperatorReturnItems"]:
|
def execute(self, context) -> set["rna_enums.OperatorReturnItems"]:
|
||||||
props = tool.Misc.get_misc_props()
|
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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ classes = (
|
|||||||
operator.SelectByProperty,
|
operator.SelectByProperty,
|
||||||
operator.SelectFilterElements,
|
operator.SelectFilterElements,
|
||||||
operator.SelectGlobalId,
|
operator.SelectGlobalId,
|
||||||
|
operator.SelectQueryElements,
|
||||||
operator.SelectIfcClass,
|
operator.SelectIfcClass,
|
||||||
operator.SelectSimilar,
|
operator.SelectSimilar,
|
||||||
operator.ShowAllElements,
|
operator.ShowAllElements,
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ from bonsai.bim.ifc import IfcStore
|
|||||||
from bonsai.bim.prop import StrProperty
|
from bonsai.bim.prop import StrProperty
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from bpy.stub_internal import rna_enums
|
||||||
|
|
||||||
from bonsai.bim.prop import BIMFacet
|
from bonsai.bim.prop import BIMFacet
|
||||||
|
|
||||||
|
|
||||||
@@ -791,6 +793,27 @@ class Search(Operator):
|
|||||||
return {"FINISHED"}
|
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):
|
class SaveSearch(Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.save_search"
|
bl_idname = "bim.save_search"
|
||||||
bl_label = "Save Search"
|
bl_label = "Save Search"
|
||||||
|
|||||||
Reference in New Issue
Block a user