| import cadquery as cq | |
| def create_bolt(params): | |
| diameter = params["diameter"] | |
| pitch = params["pitch"] | |
| thread_depth = params["thread_depth"] | |
| thread_angle = params["thread_angle"] | |
| head_shape = params["head_shape"] | |
| shank_length = params["shank_length"] | |
| # Shank | |
| bolt = cq.Workplane("XY").circle(diameter / 2).extrude(shank_length) | |
| # Head | |
| if head_shape == "hex": | |
| across_flats = diameter * 1.5 | |
| head = ( | |
| cq.Workplane("XY") | |
| .polygon(6, across_flats) | |
| .extrude(diameter * 0.6) | |
| ) | |
| else: | |
| head = ( | |
| cq.Workplane("XY") | |
| .circle(diameter) | |
| .extrude(diameter * 0.6) | |
| ) | |
| bolt = head.union(bolt.translate((0, 0, diameter * 0.6))) | |
| return bolt | |