Skip to content

Conversation

@infused-kim
Copy link

@infused-kim infused-kim commented Jul 8, 2024

Hey guys,

As previously discussed in discord here are some small contributions to the fastener module.

I added multiple things in one PR, but separated each improvement in a separate commit to make review easier. But please let me know if you prefer separate PR for each thing or only want to merge some, but not all of the suggestions.

1. HeatSetNuts from AliExpress

They can be purchased here: https://www.aliexpress.com/item/1005005220632314.html

It seems like there are multiple stores / brands that sell the same nuts (same dimensions and images). I picked this one, because he has the largest selection, a large amount of sales and was fast to respond in the support chat.

You can also find the spreadsheet I used to edit the data here:
https://docs.google.com/spreadsheets/d/1ZpZ6ltspaA5y2Nw6DH-3abuv4ToLoAWX3zQu_ON2lfs/edit?gid=0#gid=0

2. Allow nut size to have more than 3 parts

Some of the AE nuts had the same size thread size and height, but different variations in the outer diameter, such as M2-0.4-H2-D3.2 and M2-0.4-H2-D3.5 (outer diameter 3.2 vs 3.5).

So, I added another - to distinguish between them.

But then the code stopped populating length_size:

        if len(size_parts) == 3:
            self.length_size = size_parts[2]

So, I changed it to allow more than 3 parts.

Make drill tip optional in _make_fastener_hole

Something that surprised be when working with the insert holes was that the holes ended up deeper than the depth setting I specified.

The issue was that the drill_tip was added below the depth and the size of it was dependent on the width of the drill, so difficult to compensate for with a shorter drill tip.

I added a drill_tip: bool parameter that lets you control whether you want to include it.

You can test it with:

# %% Heat Set Nut - hole too deep
import build123d as bd
import bd_warehouse as bdw
import ocp_vscode as ocp

from copy import copy
from bd_warehouse import fastener


n = bdw.fastener.HeatSetNut(
    fastener_type='McMaster-Carr',
    size='M2-0.4-Short',
)

offset = 5

with bd.BuildPart() as plate:
    b = bd.Box(10, 10, 5)
    topf = b.faces().sort_by(bd.Axis.Z)[-1]
    with bd.Locations(topf):
        with bd.Locations((-offset/2, 0, 0)):
            bdw.fastener.InsertHole(
                n,
                depth=3,
            )
        with bd.Locations((+offset/2, 0, 0)):
            bdw.fastener.InsertHole(
                n,
                depth=3,
                drill_tip=False,
            )

fasteners = [
    copy(n).located(loc)
    for loc in n.hole_locations
]

plate = plate.part

plate = plate.split(bd.Plane.XZ, keep=bd.Keep.BOTTOM)
plate.color = bd.Color('gray')
plate.label = 'Plate'

ocp.show(
    [
        plate,
        fasteners,
    ],
    measure_tools=True
)

Add ability to print fastener size info in human readable format

Another challenge I faced was that the underlying data that is used to generate the fasteners was not easy to understand for humans, because it was using parameters like s, dk, m, which were not documented and required reading of ISO specifications to understand.

For screws that are strictly standardized that's fine, but for heat set nuts it would be useful to see the underlying sizes of supported nuts. That way users can easily compare the nuts in their collection or in a store to the ones that are supported in bd_warehouse.

I implemented it by adding a dictionary that describes the csv parameters:

    fastener_data = read_fastener_parameters_from_csv("heatset_nut_parameters.csv")
    fastener_data_param_names = {
        's': 'Outer Diameter (s)',
        'm': 'Height (s)',
        'dc': 'Tip Diameter (dc)',
        'knurls': 'Knurls',
        'material_thickness': 'Material Thickness',
        'drill': 'Drill Size',
        'part': 'Part #'
    }

You can access the info with...

import build123d as bd
import bd_warehouse as bdw

from bd_warehouse import fastener
from pprint import pprint

n = bdw.fastener.HeatSetNut(
    size='M2-0.4-Short', fastener_type='McMaster-Carr'
)

# Original data with params like `s`
pprint(n.nut_data)

# Human readable data
pprint(n.size_info)

# You can also get the size info for all types
pprint(bdw.fastener.HeatSetNut.size_info_for_all_types())

Or print it as a table:

# Or print it as a table with tabulate
bdw.fastener.HeatSetNut.print_size_info_for_all_types()

# Or for a specific type:
bdw.fastener.HeatSetNut.print_size_info_by_type('Hilitchi')

I am using this to allow users to select, which fastener they want to use in the 3d print using command line arguments.

It looks like this...

+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| Size      |   Outer Diameter (s) |   Height (s) |   Tip Diameter (dc) |   Knurls |   Material Thickness | Drill Size   | Part #   |
+===========+======================+==============+=====================+==========+======================+==============+==========+
| M2-0.4-3  |                  3.5 |            3 |                 2.9 |       20 |                  3.8 | #30          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M2-0.4-4  |                  3.5 |            4 |                 2.9 |       20 |                  4.8 | #30          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M2-0.4-6  |                  3.5 |            6 |                 2.9 |       20 |                  6.8 | #30          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M2-0.4-8  |                  3.5 |            8 |                 2.9 |       20 |                  8.8 | #30          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M3-0.5-6  |                  5   |            6 |                 4.3 |       20 |                  6.8 | #21          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M3-0.5-8  |                  5   |            8 |                 4.3 |       20 |                  8.8 | #21          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M3-0.5-10 |                  5   |           10 |                 4.3 |       20 |                 10.8 | #21          | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M4-0.7-8  |                  6   |            8 |                 5.3 |       20 |                  8.8 | #2           | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M4-0.7-6  |                  6   |            6 |                 5.3 |       20 |                  6.8 | #2           | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M4-0.7-10 |                  6   |           10 |                 5.3 |       20 |                 10.8 | #2           | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M5-0.8-6  |                  7   |            6 |                 6.3 |       20 |                  6.8 | F            | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M5-0.8-8  |                  7   |            8 |                 6.3 |       20 |                  8.8 | F            | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M5-0.8-10 |                  7   |           10 |                 6.3 |       20 |                 10.8 | F            | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M6-1-10   |                  8   |           10 |                 7.3 |       20 |                 10.8 | M            | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+
| M6-1-12   |                  8   |           12 |                 7.3 |       20 |                 12.8 | M            | H-THM300 |
+-----------+----------------------+--------------+---------------------+----------+----------------------+--------------+----------+

Conclusion

Let me know what you think. If you'd like to change anything, please let me know. Or just make changes in here.

@gumyr
Copy link
Owner

gumyr commented Jul 11, 2024

There is a lot of content here. I'd like to break this PR into separate PRs, one for each feature which will help with review.

However, I do have some comments:

  1. Parameters for ISO standard fasteners are common across all ISO fasteners and are defined in ISO 225. Having to repeat the names for each fastener adds a lot of duplication and opportunity for mistakes. Heatset nuts are add the complexity as they aren't necessarily standard. How about the base class defines these terms allowing derived classes to override the standard names if required?
  2. I understand the goal of drill_tip but a more descriptive name would be helpful - like add_drill_tip: bool = True or something like that. In addition, the docstrings were not changed to show this new parameter.
  3. Although not visible to users yet, I'm porting the bd_warehouse.bearings library from cq_warehouse and it uses the same methods to read and process CSV files so there shouldn't be any hard assumptions built into this layer of the code (I don't think are are any in this PR - just a heads up).

Thanks for improving bd_warehouse!

@gumyr
Copy link
Owner

gumyr commented Jul 11, 2024

I've found that I have the opposite drill tip problem with a project I'm working on - how about we add drilled: bool to Hole, CounterSinkHole, CounterBoreHole, ClearanceHole, InsertHole, TapHole, and ThreadedHole? The docstring would describe the addition of the drill tip. The defaults could be True or False - insert holes should probably be False by default at these parts are commonly 3D printed. What do you think?

@kcleung
Copy link

kcleung commented Jan 21, 2025

There is a lot of content here. I'd like to break this PR into separate PRs, one for each feature which will help with review.

However, I do have some comments:

  1. Parameters for ISO standard fasteners are common across all ISO fasteners and are defined in ISO 225. Having to repeat the names for each fastener adds a lot of duplication and opportunity for mistakes. Heatset nuts are add the complexity as they aren't necessarily standard. How about the base class defines these terms allowing derived classes to override the standard names if required?
  2. I understand the goal of drill_tip but a more descriptive name would be helpful - like add_drill_tip: bool = True or something like that. In addition, the docstrings were not changed to show this new parameter.
  3. Although not visible to users yet, I'm porting the bd_warehouse.bearings library from cq_warehouse and it uses the same methods to read and process CSV files so there shouldn't be any hard assumptions built into this layer of the code (I don't think are are any in this PR - just a heads up).

Thanks for improving bd_warehouse!

@gumyr I note that this PR was 6 months ago. And you mentioned that you were porting the bearing generator from cq_warehouse. Is this port completed?

In relation to the breaking the PR into multiple PRs, would it be possible to cherry-pick the commits, modify as you suggested, and merge the modified commits as new PR/feature? We have not heard from @infused-kim for quite a long while, yet we would love to see his work make it into bd_warehouse

@gumyr
Copy link
Owner

gumyr commented Jan 21, 2025

There are a few common bearings - here are the docs: https://bd-warehouse.readthedocs.io/en/latest/bearing.html

Normally I like to have the person that create the PR get the credit for the code but it appears that this work has been abandoned so breaking it up and resubmitting the commits would be find by me.

@kcleung
Copy link

kcleung commented Jan 27, 2025

There are a few common bearings - here are the docs: https://bd-warehouse.readthedocs.io/en/latest/bearing.html

Normally I like to have the person that create the PR get the credit for the code but it appears that this work has been abandoned so breaking it up and resubmitting the commits would be find by me.

@gumyr I just ported the commit about HexSetNuts and allowing more than three parts into a new PR #46 can you please have a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants