gumyr / cq_warehouse

A cadquery parametric part collection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom bearing sizes

cyberhuman opened this issue · comments

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!

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.

@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.

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

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

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")