From 740fcf77684909a1d560f93029d21616bc5a34fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Aliste?= Date: Tue, 10 Feb 2026 18:20:18 -0300 Subject: [PATCH] Use Blender's angle snap setting in wall.py and profile.py Replace hardcoded 5-degree angle snapping with Blender's snap_angle_increment setting in create_wall_from_2_points() and create_profile_from_2_points(). Co-Authored-By: Claude Opus 4.5 --- src/bonsai/bonsai/bim/module/model/profile.py | 6 +++--- src/bonsai/bonsai/bim/module/model/wall.py | 4 ++-- src/bonsai/bonsai/tool/snap.py | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/profile.py b/src/bonsai/bonsai/bim/module/model/profile.py index 572898c484..4e16f9b296 100644 --- a/src/bonsai/bonsai/bim/module/model/profile.py +++ b/src/bonsai/bonsai/bim/module/model/profile.py @@ -17,7 +17,7 @@ # along with Bonsai. If not, see . import copy -from math import atan2, degrees, pi +from math import atan2, degrees, pi, radians from typing import Any, Literal, Optional, Union import bmesh @@ -195,8 +195,8 @@ class DumbProfileGenerator: if should_round: # Round to nearest 50mm (yes, metric for now) self.length = 0.05 * round(length / 0.05) - # Round to nearest 5 degrees - nearest_degree = (pi / 180) * 5 + angle_snap = tool.Snap.get_angle_snap_value(bpy.context) + nearest_degree = radians(angle_snap) self.rotation = nearest_degree * round(self.rotation / nearest_degree) self.location = coords[0] data["obj"] = self.create_profile() diff --git a/src/bonsai/bonsai/bim/module/model/wall.py b/src/bonsai/bonsai/bim/module/model/wall.py index ba3d93586b..7f4579df31 100644 --- a/src/bonsai/bonsai/bim/module/model/wall.py +++ b/src/bonsai/bonsai/bim/module/model/wall.py @@ -916,8 +916,8 @@ class DumbWallGenerator: if should_round: # Round to nearest 50mm (yes, metric for now) self.length = 0.05 * round(length / 0.05) - # Round to nearest 5 degrees - nearest_degree = (math.pi / 180) * 5 + angle_snap = tool.Snap.get_angle_snap_value(bpy.context) + nearest_degree = math.radians(angle_snap) self.rotation = nearest_degree * round(self.rotation / nearest_degree) self.location = coords[0] data["obj"] = self.create_wall() diff --git a/src/bonsai/bonsai/tool/snap.py b/src/bonsai/bonsai/tool/snap.py index 7ee06cd44e..bc35505826 100644 --- a/src/bonsai/bonsai/tool/snap.py +++ b/src/bonsai/bonsai/tool/snap.py @@ -118,10 +118,14 @@ class Snap(bonsai.core.tool.Snap): def get_angle_snap_value(cls, context: bpy.types.Context) -> float: """Get the angle snap increment from Blender's tool settings. + Uses snap_angle_increment_3d (Blender 5.0+) or snap_angle_increment (Blender 4.x). + :param context: Blender context :return: Angle snap increment in degrees """ - return context.scene.tool_settings.snap_angle_increment + if bpy.app.version >= (5, 0, 0): + return math.degrees(context.scene.tool_settings.snap_angle_increment_3d) + return math.degrees(context.scene.tool_settings.snap_angle_increment) @classmethod def get_snap_points_on_raycasted_face(cls, context, event, obj, face_index):