File size: 4,101 Bytes
6de1b61 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | from __future__ import annotations
import argparse
import json
from pathlib import Path
import cadquery as cq
from cadquery import exporters
def build_fixture() -> cq.Workplane:
base_width = 50
base_height = 80
base_thickness = 6
corner_radius = 4
hole_dia = 5.2
csk_dia = 10
csk_angle = 82
hole_inset_x = 10
hole_inset_y = 12
shaft_width = 14
shaft_depth = 12
shaft_length = 35
hook_inner_radius = 16
hook_outer_radius = hook_inner_radius + shaft_depth
gusset_thickness = 6
bottom_gusset_length = 25
bottom_gusset_height = 18
top_gusset_length = 15
top_gusset_height = 12
base = (
cq.Workplane("XY")
.box(base_width, base_height, base_thickness)
.edges("|Z")
.fillet(corner_radius)
)
hx = base_width / 2 - hole_inset_x
hy = base_height / 2 - hole_inset_y
pts = [(hx, hy), (-hx, hy), (hx, -hy), (-hx, -hy)]
base = (
base.faces(">Z")
.workplane()
.pushPoints(pts)
.cskHole(diameter=hole_dia, cskDiameter=csk_dia, cskAngle=csk_angle)
)
z_start = base_thickness / 2
z_arc_center = z_start + shaft_length
y_inner_start = shaft_depth / 2
y_outer_start = -shaft_depth / 2
hook = (
cq.Workplane("YZ")
.moveTo(y_outer_start, z_start)
.lineTo(y_outer_start, z_arc_center)
.threePointArc(
(y_outer_start + hook_outer_radius, z_arc_center + hook_outer_radius),
(y_outer_start + 2 * hook_outer_radius, z_arc_center),
)
.threePointArc(
(y_outer_start + 2 * hook_outer_radius - shaft_depth / 2, z_arc_center - shaft_depth / 2),
(y_outer_start + 2 * hook_outer_radius - shaft_depth, z_arc_center),
)
.threePointArc(
(y_inner_start + hook_inner_radius, z_arc_center + hook_inner_radius),
(y_inner_start, z_arc_center),
)
.lineTo(y_inner_start, z_start)
.close()
.extrude(shaft_width / 2, both=True)
)
bottom_gusset = (
cq.Workplane("YZ")
.moveTo(y_outer_start, z_start)
.lineTo(y_outer_start - bottom_gusset_length, z_start)
.lineTo(y_outer_start, z_start + bottom_gusset_height)
.close()
.extrude(gusset_thickness / 2, both=True)
)
top_gusset = (
cq.Workplane("YZ")
.moveTo(y_inner_start, z_start)
.lineTo(y_inner_start + top_gusset_length, z_start)
.lineTo(y_inner_start, z_start + top_gusset_height)
.close()
.extrude(gusset_thickness / 2, both=True)
)
return base.union(hook).union(bottom_gusset).union(top_gusset)
def main() -> None:
parser = argparse.ArgumentParser(description="Build the CadQuery heavy-duty hook sample.")
parser.add_argument("--out-dir", required=True)
args = parser.parse_args()
out_dir = Path(args.out_dir)
out_dir.mkdir(parents=True, exist_ok=True)
stl_path = out_dir / "heavy_duty_hook.stl"
fixture = build_fixture()
exporters.export(fixture, str(stl_path))
bbox = fixture.val().BoundingBox()
print(
json.dumps(
{
"name": "Heavy_Duty_Hook",
"stl_path": str(stl_path),
"bounding_box": {
"xlen": bbox.xlen,
"ylen": bbox.ylen,
"zlen": bbox.zlen,
"xmin": bbox.xmin,
"xmax": bbox.xmax,
"ymin": bbox.ymin,
"ymax": bbox.ymax,
"zmin": bbox.zmin,
"zmax": bbox.zmax,
},
"cadquery_features": [
"filleted base plate",
"four countersunk mounting holes",
"sketched curved J hook profile",
"bottom triangular gusset",
"top triangular gusset",
"single CadQuery unioned fixture",
],
}
)
)
if __name__ == "__main__":
main()
|