From 6f7565f6f98ce04456ca546cf89fd5de251f3fa7 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Mon, 25 Nov 2024 22:12:27 -0600 Subject: [PATCH] select objects within a certain tolerance--which is set in the preferences. --- src/bonsai/bonsai/bim/module/drawing/prop.py | 1 + .../bonsai/bim/module/search/operator.py | 20 ++++++++++++++++++- src/bonsai/bonsai/bim/ui.py | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/prop.py b/src/bonsai/bonsai/bim/module/drawing/prop.py index 84f7670949..fdc7b28160 100644 --- a/src/bonsai/bonsai/bim/module/drawing/prop.py +++ b/src/bonsai/bonsai/bim/module/drawing/prop.py @@ -401,6 +401,7 @@ class DocProperties(PropertyGroup): drawing_font: StringProperty(default="OpenGost Type B TT.ttf", name="Drawing Font") magic_font_scale: bpy.props.FloatProperty(default=0.004118616, name="Font Scale Factor") imperial_precision: StringProperty(default="1/32", name="Imperial Precision") + tolerance: bpy.props.FloatProperty(default=0.00001, name="A tolerance used when selecting objects") class BIMCameraProperties(PropertyGroup): diff --git a/src/bonsai/bonsai/bim/module/search/operator.py b/src/bonsai/bonsai/bim/module/search/operator.py index d6e68f3224..af27becd4b 100644 --- a/src/bonsai/bonsai/bim/module/search/operator.py +++ b/src/bonsai/bonsai/bim/module/search/operator.py @@ -717,6 +717,15 @@ class SelectSimilar(Operator, tool.Ifc.Operator): if key == "PredefinedType": key = "predefined_type" value = ifcopenshell.util.selector.get_element_value(element, key) + tolerance = bpy.context.scene.DocProperties.tolerance + + + # Determine the number of decimal places based on the magnitude of the rounding value + if tolerance < 1: + decimal_places = max(0, -int(f"{tolerance:.1e}".split('e')[-1])) # Exponent in scientific notation + formatted_tolerance = f"{tolerance:.{decimal_places}f}" + else: + formatted_tolerance = f"{tolerance:.1f}" # For values >= 1, one decimal place is enough if self.calculate_sum and isinstance(value, (int, float)): total = 0 @@ -736,5 +745,14 @@ class SelectSimilar(Operator, tool.Ifc.Operator): element = tool.Ifc.get_entity(obj) if not element: continue - if ifcopenshell.util.selector.get_element_value(element, key) == value: + obj_value = ifcopenshell.util.selector.get_element_value(element, key) + if isinstance(obj_value, (int, float)): + # Check within rounding value + if abs(obj_value - value) <= tolerance: + obj.select_set(True) + elif obj_value == value: obj.select_set(True) + if isinstance(value, (int, float)): + self.report({"INFO"}, f"Selected all objects that share the same ({key}) value--within a ({formatted_tolerance}) tolerance.") + else: + self.report({"INFO"}, f"Selected all objects that share the same ({key}) value") \ No newline at end of file diff --git a/src/bonsai/bonsai/bim/ui.py b/src/bonsai/bonsai/bim/ui.py index fbbea1d61f..e56a501d22 100644 --- a/src/bonsai/bonsai/bim/ui.py +++ b/src/bonsai/bonsai/bim/ui.py @@ -380,7 +380,8 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): row.prop(context.scene.DocProperties, "magic_font_scale") row = self.layout.row() row.prop(context.scene.DocProperties, "imperial_precision") - + row = self.layout.row() + row.prop(context.scene.DocProperties, "tolerance") # Scene panel groups class BIM_PT_tabs(Panel):