mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Support arbitrary element selection for manual groups in search / IfcCSV, with support for huge element selections.
This commit is contained in:
@@ -325,6 +325,10 @@ def draw_filter(layout, props, data, module):
|
|||||||
elif ifc_filter.type == "instance":
|
elif ifc_filter.type == "instance":
|
||||||
row = box.row(align=True)
|
row = box.row(align=True)
|
||||||
row.prop(ifc_filter, "value", text="", icon="GRIP")
|
row.prop(ifc_filter, "value", text="", icon="GRIP")
|
||||||
|
op = row.operator("bim.select_filter_elements", text="", icon="EYEDROPPER")
|
||||||
|
op.group_index = i
|
||||||
|
op.index = j
|
||||||
|
op.module = module
|
||||||
op = row.operator("bim.remove_filter", text="", icon="X")
|
op = row.operator("bim.remove_filter", text="", icon="X")
|
||||||
op.group_index = i
|
op.group_index = i
|
||||||
op.index = j
|
op.index = j
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ classes = (
|
|||||||
operator.RemoveAllCsvAttributes,
|
operator.RemoveAllCsvAttributes,
|
||||||
operator.ExportIfcCsv,
|
operator.ExportIfcCsv,
|
||||||
operator.ImportIfcCsv,
|
operator.ImportIfcCsv,
|
||||||
operator.EyedropIfcCsv,
|
|
||||||
operator.SelectCsvIfcFile,
|
operator.SelectCsvIfcFile,
|
||||||
operator.ImportCsvAttributes,
|
operator.ImportCsvAttributes,
|
||||||
operator.ExportCsvAttributes,
|
operator.ExportCsvAttributes,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class RemoveAllCsvAttributes(bpy.types.Operator):
|
|||||||
|
|
||||||
class ImportCsvAttributes(bpy.types.Operator):
|
class ImportCsvAttributes(bpy.types.Operator):
|
||||||
bl_idname = "bim.import_csv_attributes"
|
bl_idname = "bim.import_csv_attributes"
|
||||||
bl_label = "Import CSV Template"
|
bl_label = "Load CSV Settings"
|
||||||
bl_description = "Import a json template for CSV export"
|
bl_description = "Import a json template for CSV export"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
filter_glob: bpy.props.StringProperty(default="*.json", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.json", options={"HIDDEN"})
|
||||||
@@ -93,7 +93,7 @@ class ImportCsvAttributes(bpy.types.Operator):
|
|||||||
|
|
||||||
class ExportCsvAttributes(bpy.types.Operator):
|
class ExportCsvAttributes(bpy.types.Operator):
|
||||||
bl_idname = "bim.export_csv_attributes"
|
bl_idname = "bim.export_csv_attributes"
|
||||||
bl_label = "Export CSV Template"
|
bl_label = "Save CSV Settings"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
bl_description = "Save a json template for CSV export"
|
bl_description = "Save a json template for CSV export"
|
||||||
filename_ext = ".json"
|
filename_ext = ".json"
|
||||||
@@ -197,24 +197,6 @@ class ImportIfcCsv(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class EyedropIfcCsv(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.eyedrop_ifccsv"
|
|
||||||
bl_label = "Query Selected Items"
|
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
global_ids = []
|
|
||||||
self.file = IfcStore.get_file()
|
|
||||||
for obj in context.selected_objects:
|
|
||||||
element = tool.Ifc.get_entity(obj)
|
|
||||||
if element:
|
|
||||||
global_id = getattr(element, "GlobalId", None)
|
|
||||||
if global_id:
|
|
||||||
global_ids.append(global_id)
|
|
||||||
context.scene.CsvProperties.ifc_selector = ",".join(global_ids)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class SelectCsvIfcFile(bpy.types.Operator):
|
class SelectCsvIfcFile(bpy.types.Operator):
|
||||||
bl_idname = "bim.select_csv_ifc_file"
|
bl_idname = "bim.select_csv_ifc_file"
|
||||||
bl_label = "Select CSV IFC File"
|
bl_label = "Select CSV IFC File"
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ classes = (
|
|||||||
operator.SaveSearch,
|
operator.SaveSearch,
|
||||||
operator.SaveSelectorQuery,
|
operator.SaveSelectorQuery,
|
||||||
operator.Search,
|
operator.Search,
|
||||||
|
operator.SelectFilterElements,
|
||||||
operator.SelectGlobalId,
|
operator.SelectGlobalId,
|
||||||
operator.SelectIfcClass,
|
operator.SelectIfcClass,
|
||||||
operator.SelectSimilar,
|
operator.SelectSimilar,
|
||||||
|
|||||||
@@ -120,6 +120,37 @@ class AddFilter(Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class SelectFilterElements(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.select_filter_elements"
|
||||||
|
bl_label = "Select Filter Elements"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
group_index: IntProperty()
|
||||||
|
index: IntProperty()
|
||||||
|
module: StringProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if self.module == "search":
|
||||||
|
props = context.scene.BIMSearchProperties
|
||||||
|
elif self.module == "csv":
|
||||||
|
props = context.scene.CsvProperties
|
||||||
|
global_ids = []
|
||||||
|
for obj in context.selected_objects:
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
if element:
|
||||||
|
global_id = getattr(element, "GlobalId", None)
|
||||||
|
if global_id:
|
||||||
|
global_ids.append(global_id)
|
||||||
|
if len(global_ids) > 50:
|
||||||
|
# Too much to store in a string property
|
||||||
|
name = "globalid-filter-" + ifcopenshell.guid.new()
|
||||||
|
text_data = bpy.data.texts.new(name)
|
||||||
|
text_data.from_string(",".join(global_ids))
|
||||||
|
props.filter_groups[self.group_index].filters[self.index].value = f"bpy.data.texts['{name}']"
|
||||||
|
else:
|
||||||
|
props.filter_groups[self.group_index].filters[self.index].value = ",".join(global_ids)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class Search(Operator):
|
class Search(Operator):
|
||||||
bl_idname = "bim.search"
|
bl_idname = "bim.search"
|
||||||
bl_label = "Search"
|
bl_label = "Search"
|
||||||
|
|||||||
@@ -26,7 +26,11 @@ class Search(blenderbim.core.tool.Search):
|
|||||||
continue
|
continue
|
||||||
if ifc_filter.type == "instance":
|
if ifc_filter.type == "instance":
|
||||||
has_instance_or_entity_filter = True
|
has_instance_or_entity_filter = True
|
||||||
filter_group_query.append(ifc_filter.value)
|
if "bpy.data.texts" in ifc_filter.value:
|
||||||
|
data_name = ifc_filter.value.split("bpy.data.texts")[1][2:-2]
|
||||||
|
filter_group_query.append(bpy.data.texts[data_name].as_string())
|
||||||
|
else:
|
||||||
|
filter_group_query.append(ifc_filter.value)
|
||||||
elif ifc_filter.type == "entity":
|
elif ifc_filter.type == "entity":
|
||||||
has_instance_or_entity_filter = True
|
has_instance_or_entity_filter = True
|
||||||
filter_group_query.append(ifc_filter.value)
|
filter_group_query.append(ifc_filter.value)
|
||||||
@@ -92,7 +96,23 @@ class ImportFilterQueryTransformer(lark.Transformer):
|
|||||||
|
|
||||||
def facet_list(self, args):
|
def facet_list(self, args):
|
||||||
new = self.filter_groups.add()
|
new = self.filter_groups.add()
|
||||||
|
global_ids = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
|
if arg["type"] == "instance" and global_ids:
|
||||||
|
if "bpy.data.texts" in new2.value:
|
||||||
|
data_name = new2.value.split("bpy.data.texts")[1][2:-2]
|
||||||
|
bpy.data.texts[data_name].write("," + arg["value"])
|
||||||
|
elif len(new2.value) > (23 * 50):
|
||||||
|
name = "globalid-filter-" + ifcopenshell.guid.new()
|
||||||
|
text_data = bpy.data.texts.new(name)
|
||||||
|
text_data.from_string(new2.value + "," + arg["value"])
|
||||||
|
new2.value = f"bpy.data.texts['{name}']"
|
||||||
|
else:
|
||||||
|
new2.value += "," + arg["value"]
|
||||||
|
continue
|
||||||
|
global_ids = []
|
||||||
|
if arg["type"] == "instance":
|
||||||
|
global_ids.append(arg["value"])
|
||||||
new2 = new.filters.add()
|
new2 = new.filters.add()
|
||||||
new2.type = arg["type"]
|
new2.type = arg["type"]
|
||||||
new2.value = arg["value"]
|
new2.value = arg["value"]
|
||||||
|
|||||||
Reference in New Issue
Block a user