mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
display the sum of all selected objects
This commit is contained in:
@@ -102,6 +102,11 @@ def draw_psetqto_ui(
|
||||
allow_removing: bool = True,
|
||||
filter_keyword: str = "",
|
||||
) -> None:
|
||||
|
||||
|
||||
select_similar_op = context.active_operator
|
||||
calculated_sum = getattr(select_similar_op, "calculated_sum", 0.0)
|
||||
|
||||
filter_keyword = filter_keyword.lower()
|
||||
box = layout.box()
|
||||
row = box.row(align=True)
|
||||
@@ -195,7 +200,10 @@ def draw_psetqto_ui(
|
||||
row.label(text=prop["Name"])
|
||||
op = row.operator("bim.select_similar", text=nominal_value, icon="NONE", emboss=False)
|
||||
op.key = '"' + pset["Name"].replace('"', '\\"') + '"."' + prop["Name"].replace('"', '\\"') + '"'
|
||||
|
||||
# calculate sum of all selected objects
|
||||
if select_similar_op:
|
||||
if op.key == select_similar_op.key and calculated_sum != 0 and isinstance(float(nominal_value), (int, float)):
|
||||
row.label(text=f"(Sum: {calculated_sum})")
|
||||
if not has_props_displayed:
|
||||
row = box.row()
|
||||
row.scale_y = 0.8
|
||||
|
||||
@@ -696,8 +696,19 @@ class SelectSimilar(Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.select_similar"
|
||||
bl_label = "Select Similar"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_description = (
|
||||
"Select objects with a similar value\n\n"
|
||||
+ "SHIFT+CLICK display the sum of all selected objects"
|
||||
)
|
||||
|
||||
key: bpy.props.StringProperty()
|
||||
calculate_sum: bpy.props.BoolProperty(name="Calculate Sum of Selected Objects", default=False, options={"SKIP_SAVE"})
|
||||
calculated_sum: bpy.props.FloatProperty(name="Calculated Sum", default=0.0)
|
||||
|
||||
def invoke(self, context, event):
|
||||
if event.type == "LEFTMOUSE" and event.shift:
|
||||
self.calculate_sum = True
|
||||
return self.execute(context)
|
||||
|
||||
def _execute(self, context):
|
||||
props = context.scene.BIMSearchProperties
|
||||
@@ -707,9 +718,26 @@ class SelectSimilar(Operator, tool.Ifc.Operator):
|
||||
if key == "PredefinedType":
|
||||
key = "predefined_type"
|
||||
value = ifcopenshell.util.selector.get_element_value(element, key)
|
||||
for obj in context.visible_objects:
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if not element:
|
||||
continue
|
||||
if ifcopenshell.util.selector.get_element_value(element, key) == value:
|
||||
obj.select_set(True)
|
||||
|
||||
|
||||
if self.calculate_sum and isinstance(value, (int, float)):
|
||||
total = 0
|
||||
for obj in context.selected_objects:
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if not element:
|
||||
continue
|
||||
value = ifcopenshell.util.selector.get_element_value(element, key)
|
||||
if value:
|
||||
total += value
|
||||
self.calculated_sum = total
|
||||
bpy.context.window_manager.clipboard = str(self.calculated_sum)
|
||||
self.report({"INFO"}, f"({self.calculated_sum}) was copied to the clipboard.")
|
||||
else:
|
||||
self.calculated_sum = 0
|
||||
for obj in context.visible_objects:
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if not element:
|
||||
continue
|
||||
if ifcopenshell.util.selector.get_element_value(element, key) == value:
|
||||
obj.select_set(True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user