Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Schultz cc90340b3b tweaked active operator 2024-10-26 14:22:18 -05:00
Ryan Schultz db075c7160 display the sum of all selected objects 2024-10-26 13:26:11 -05:00
2 changed files with 45 additions and 7 deletions
+11 -1
View File
@@ -102,6 +102,11 @@ def draw_psetqto_ui(
allow_removing: bool = True,
filter_keyword: str = "",
) -> None:
active_operator = context.active_operator
filter_keyword = filter_keyword.lower()
box = layout.box()
row = box.row(align=True)
@@ -195,7 +200,12 @@ 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 active_operator:
if active_operator.bl_idname == "BIM_OT_select_similar":
calculated_sum = getattr(active_operator, "calculated_sum", 0.0)
if op.key == active_operator.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)