Repository navigation
Add a tool to generate a hexagonal recess - #61
RazorSh4rk wants to merge 3 commits into
Conversation
Add a Hex Nut Hole command that cuts a hexagonal recess at the end of a PartDesign Hole feature. Supports a radius, recess depth, entry or opposite face, and a 30 degree rotation.
|
Addresses #34 I guess but honestly I didn't even see that request |
|
Looks like useful extension to the Hole Wizard. I'd certainly make use of it. |
Rahix
left a comment
There was a problem hiding this comment.
Hi! First of all, thanks a lot for sending this pull request, this is a very cool addition to FusedFilamentDesign! I very much appreciate your efforts to align your code with the style of the codebase of this addon.
I have some thoughts on your implementation, please check my comments below :)
Re. testing: Once we have settled on the general implementation, I'll show you how the test infrastructure works so we can add tests for the new feature as well!
| self.form = Gui.PySideUic.loadUi(Utils.Resources.get_panel("ffDesign_HexNut.ui")) | ||
|
|
||
| self.form.HexNutRadius.setProperty("rawValue", 3.2) | ||
| self.form.HexNutDepth.setProperty("rawValue", 3.0) |
There was a problem hiding this comment.
So HexNutRadius then becomes HexNutSize.
I think it would be very nice to prefill HexNutRadius and HexNutDepth correctly based on the Hole parameters. Since the Hole usually references a standard thread size, we can automatically set the correct hex nut size based on standard nut sizes (e.g. ISO 4032 for metric).
To do this, you can use a similar approach to what we did in ffDesign_RibThreads.py:
FusedFilamentDesign/ffDesign_RibThreads.py
Lines 37 to 48 in 870e5db
FusedFilamentDesign/ffDesign_RibThreads.py
Lines 448 to 484 in 870e5db
So in your case, something like:
HEX_NUT_PARAMETERS = {
"ISOMetricProfile": {
"M3": HexNutParameters(name="M3", normative=3, across_flats= 5.5, height= 2.4),
"M4": HexNutParameters(name="M4", normative=4, across_flats= 7.0, height= 3.3),
"M5": HexNutParameters(name="M5", normative=5, across_flats= 8.0, height= 4.7),
"M6": HexNutParameters(name="M6", normative=6, across_flats=10.0, height= 5.2),
"M8": HexNutParameters(name="M8", normative=8, across_flats=13.0, height= 6.8),
},
"UNC": {
"1/4": HexNutParameters(name="1/4-20", normative=6.35, across_flats=11.1, height= 5.7),
},
}Ontop of this, I would add a fixed clearance of 0.2 mm to both dimensions. So for M4, the values would then end up 7.2 mm (size) and 3.5 mm (height/depth).
For UX purposes, I would add a message text in the task panel which tells you whether a standard size was applied or not:
- If yes, I would suggest it reads in green: Applied standard <metric/imperial> nut size for <Hole standard, e.g. M5> plus 0.2 mm clearance.
- If no, I would make it read in red: Non-standard hole size. Please set hex nut size accordingly.
Maybe even set the field to an illegal value (0?) at first so you have to set an appropriate value yourself before the tool can proceed.
Here's a reference for such a status message:
FusedFilamentDesign/ffDesign_RibThreads.py
Lines 517 to 528 in 870e5db
There was a problem hiding this comment.
I am strongly against adding tolerances by default in CAD, especially if they are silent; consider slicer settings accounting for shrinkage, now the hole will have a 0.4mm tolerance, which makes it unusable for ~m3 or smaller, without any user warning. Otherwise I agree with the approach.
There was a problem hiding this comment.
The 0.2mm i suggested is not tolerance, it is clearance. Similar to how through-holes for screws are over-dimensioned from the normative size by default. If you need additional size for tolerance, that is indeed something to be added by the slicer/manually.
I'll see if it makes sense to add something like
if radius between 2.8 and 3.2: m3 nut
There is prior art for this in the fasteners workbench. They essentially just walk the table of normative thread sizes and choose the first where the hole diameter is bigger than the normative one.
I am okay with adding similar logic here, but do keep in mind that this will need a metric/imperial switch still, to be unambiguous.
My suggestion: If the hole has a thead set, choose based on this info as it is the most reliable. If it doesn't, add two buttons: Auto ISO 4032 nut size and Auto [freedom equivalent] nut size which, when pressed, do the guessing logic.
What do you think?
|
|
||
| # A regular hexagon has 6-fold symmetry, so a 60 degree turn looks the | ||
| # same. Turning it by 30 degrees is what swaps a flat side and a vertex. | ||
| rotation = math.radians(30) if vertex_up else 0.0 |
There was a problem hiding this comment.
Can we make the rotation another configurable property on the Hole? I would leave the checkbox in the task dialog to quickly select either option, but have a HexNutRotation property where you can enter an arbitrary rotation value in case you ever need something non-standard.
| nut_radius: App.Units.Quantity, | ||
| nut_depth: App.Units.Quantity, | ||
| far_side: bool = False, | ||
| vertex_up: bool = False, |
There was a problem hiding this comment.
I think for the sake of clean abstraction, make_hex_nuts() should already get a
rotation: Apps.Units.Quantity instead of a vertex_up: bool.
| # Fix every vertex directly. Equal sides plus points on a circle also | ||
| # allows a collapsed hexagon, so all vertices get their own coordinates. | ||
| x = hole_loc.x_expr | ||
| y = hole_loc.y_expr | ||
| r = f"({radius_expr})" | ||
| vertex_offsets = [] | ||
| for i in range(HEX_SIDES): | ||
| angle = 2 * math.pi / HEX_SIDES * i + rotation | ||
| vertex_offsets.append((f"{r} * {math.cos(angle)!r}", f"{r} * {math.sin(angle)!r}")) | ||
|
|
||
| expressions = [] | ||
| for dx, dy in vertex_offsets: | ||
| expressions.append(f"{x} + ({dx})") | ||
| expressions.append(f"{y} + ({dy})") | ||
|
|
||
| last_c = len(sketch.Constraints) | ||
| new_constraints = [] | ||
| for i in range(HEX_SIDES): | ||
| new_constraints.append(Sketcher.Constraint("DistanceX", last_geo_id + i, 1, 0)) | ||
| new_constraints.append(Sketcher.Constraint("DistanceY", last_geo_id + i, 1, 0)) | ||
| sketch.addConstraint(new_constraints) | ||
| for i, expr in enumerate(expressions): | ||
| sketch.setExpression(f"Constraints[{last_c + i}]", expr) |
There was a problem hiding this comment.
I absolutely agree that you have to add DistanceX/Y constraints here for robust parametricity, but I find the way you add them is very convoluted. Why not do this in a single for loop?
# Not verified...
last_c = len(sketch.Constraints)
for i in range(HEX_SIDES):
angle = 2 * math.pi / HEX_SIDES * i + rotation
sketch.addConstraint(Sketcher.Constraint("DistanceX", last_geo_id + i, 1, 0))
sketch.setExpression(
f"Constraints[{last_c + i * 2}]",
f"{hole_loc.x_expr} + {radius_expr} * {math.cos(angle)!r}",
)
sketch.addConstraint(Sketcher.Constraint("DistanceY", last_geo_id + i, 1, 0))
sketch.setExpression(
f"Constraints[{last_c + i * 2 + 1}]",
f"{hole_loc.x_expr} + {radius_expr} * {math.sin(angle)!r}",
)| # Each hole can exit through a face at a different distance, and a sketch | ||
| # is planar. So on the opposite side, every hole gets its own sketch. | ||
| offsets = [ | ||
| (hole_loc, _get_far_face_offset(body, hole, profile_sketch, hole_loc)) for hole_loc in hole_locations | ||
| ] | ||
| multiple = len(offsets) > 1 | ||
| for i, (hole_loc, offset) in enumerate(offsets): |
There was a problem hiding this comment.
I don't quite agree with the approach to give every hole a unique offset. In practice, I would usually want to use the same length of screw for each hole, even if the far faces of each one are different amounts away.
So rather, the distance between the "near face" and the depth of the hex hole should be the same distance for each one. This then allows you to again only generate a single pocket for all hex nut holes.
We still need to calculate the offsets for each hole, to figure out the minimum and maximum far face distance. I would place the sketch at the minimum offset. Then make the pocket two-sided. First length is the nut depth. Second length is the difference between minimum and maximum (if 0, don't make two sided).
The offset should also become a parametric property, in my eyes.
Hope this makes some sense?
However, this will need consideration for the task panel UI. Just a wild suggestion, feel free to propose alternatives:
Hex Nut Size [ 7.2 mm ]
Hex Nut Depth [ 3.6 mm ]
[x] Reverse and offset for opposite side
[x] Automatic offset and opposide depth
Offset [ 0.0 mm ] # Either a manual offset from the
# hole sketch plane (0 by default) or filled
# automatically when the automatic
# checkbox is set above.
( ) Opposite through all
(o) Opposite depth
Opposite depth [ 10.0 mm ] # Automatic or manual "difference"
What are your thoughts?

Add a Hex Nut Hole command that cuts a hexagonal recess at the end of a PartDesign Hole feature.
Tried to comply with repo rules but I have no idea how to do automated testing other than using my eyeballs to look at the CAD.