Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom bearing sizes #80

Open
cyberhuman opened this issue May 2, 2023 · 5 comments
Open

Custom bearing sizes #80

cyberhuman opened this issue May 2, 2023 · 5 comments

Comments

@cyberhuman
Copy link

Hello! First of all, thank you for this great piece of work!

I wanted to use it but the size of the bearing I want to use in my design (M5-14-5) is not in the database.
How do I extend the database so my CQ project remains portable? The documentation says:

See Extending the fastener sub-package (these instructions apply to bearings as well) for guidance on how to easily add new sizes or entirely new types of bearings.

and then

As mentioned previously, the data used to guide the creation of fastener objects is derived from .csv files found in the same place as the source code. One can add to the set of standard sized fasteners by inserting appropriate data into the tables.

So am I supposed to modify the source code of cq_warehouse? I've checked the code and it seems the only place the file(s) are read from is the package's directory:

with pkg_resources.open_text(cq_warehouse, filename) as csvfile:

Do I miss anything? Any suggestions how to solve this issue? Thank you!

@gumyr
Copy link
Owner

gumyr commented May 2, 2023

There are an almost unlimited number of possible bearings out there so not all of them are modelled. As you quote above, all of the bearings are created from data files which you can customize to create the size you need. First you need to know what type of bearing and map that to a .csv file - e.g. single_row_deep_groove_ball_bearing_parameters.csv. If you open this file you'll see this:
image
which is the data that is used to create the bearing. Just add a new row for M5-14-5 with the appropriate dimensions and save the file back to where pip installed it and that new bearing will be available to you.

@cyberhuman
Copy link
Author

@gumyr thanks, that's what I understood. But that makes my project not portable :-( What happens if I want to open it on my other workstation, or to share it with someone? And then my changes will be lost if I reinstall or update the package.

@gumyr
Copy link
Owner

gumyr commented May 2, 2023

I'm sorry that cq_warehouse isn't suitable for your needs.

@cyberhuman
Copy link
Author

Maybe it's possible to make it possible to construct instances of bearings, screws etc by providing their parameters directly?

@cyberhuman
Copy link
Author

I solved my issue using the following code, borrowed and modified from the cq_warehouse's source code:

def read_fastener_parameters_from_csv(filename: str) -> dict:
    """Parse a csv parameter file into a dictionary of strings"""
    parameters = {}
    with open(filename, mode='r', newline='', encoding='utf-8') as csvfile:
        reader = csv.DictReader(csvfile)
        fieldnames = reader.fieldnames
        for row in reader:
            key = row[fieldnames[0]]
            row.pop(fieldnames[0])
            parameters[key] = row
    return parameters

class CustomSingleRowDeepGrooveBallBearing(SingleRowDeepGrooveBallBearing):
    """Custom Single Row Deep Groove Ball Bearing"""
    bearing_data = read_fastener_parameters_from_csv("bearing.csv")

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

No branches or pull requests

2 participants