bambu-printer-mcp 1.1.89 → 1.1.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ """Ergonomic file handle with an oval palm swell
2
+ Pattern: loft through several sections of different shape (circle to ovals), then fillet the end into a dome
3
+ Modelled on: Bahco ERGO 9-485 oval file handle (https://www.klium.nl/en/bahco-9-485-06-10-oval-shaped-handle-ergo-for-medium-flat-and-semi-circular-files-diameter-6-mm-76671)
4
+ Published sizes used: tang bore = 6 for medium files (retailer, Bahco 9-485-06, URL above); length = 110 (maker, Facom MAN.2 wood file handle, https://www.facom.com/product/man2/28mm-file-and-rasp-wood-handle); power-grip handle diameter 30 to 50, about 40 best, and handle length at least 100 (CCOHS, https://ccohs.ca/oshanswers/ergonomics/handtools/tooldesign.html); the swell here is 36 x 30. Waist, collar, butt and tang depth are design choices.
5
+ Concept: A push-on handle for a medium hand file (6 mm tang). The round collar at the front stands in for a steel ferrule and stops the fingers; behind it a round waist for thumb and forefinger swells into an oval that fills the palm (oval, so the hand feels which way the file faces and it cannot roll), then narrows to a domed butt the heel of the hand pushes on. The file's tapered tang is heated and pressed into the tapered hole. Prints as modelled, STANDING on the collar, no supports: every layer is then a closed ring round the tang, so the tang wedging the hole open cannot split it, and the swell and dome need nothing under them. The cost is that bending at the waist pulls layers apart, the weak direction; a file mostly pushes along the handle, so the waist is kept 20 mm thick with 5 walls. For a tool you lever with, print it lying down with supports instead. PETG. One body.
6
+ What makes this good: every section is sized for a part of the hand, and the loft joins them in one smooth skin.
7
+ """
8
+ from build123d import *
9
+
10
+ P = {
11
+ "length": 110.0, # overall (Facom MAN.2)
12
+ "collar_d": 25.0, # front collar: finger stop and printed ferrule; also the foot it prints on
13
+ "collar_len": 10.0, # collar length
14
+ "waist_d": 20.0, # round waist for thumb and forefinger, just behind the collar
15
+ "swell_z": 66.0, # height of the palm swell above the collar end (where the palm closes)
16
+ "swell_w": 36.0, # palm swell width (CCOHS power grip 30 to 50)
17
+ "swell_t": 30.0, # palm swell thickness; less than the width so the hand can feel the file's angle
18
+ "butt_w": 18.0, # width of the end face before it is domed
19
+ "butt_t": 15.0, # thickness of the end face before it is domed
20
+ "dome_r": 6.5, # fillet that turns the end face into a dome for the heel of the hand
21
+ "tang_d": 6.0, # tang hole at the mouth (Bahco 9-485-06)
22
+ "tang_tip_d": 3.0, # tang hole at its far end: tangs taper
23
+ "tang_depth": 60.0, # tang hole depth
24
+ "fit": 0.3, # print allowance added to both tang hole diameters
25
+ }
26
+
27
+
28
+ def build():
29
+ L, z0 = P["length"], P["collar_len"]
30
+ zs = P["swell_z"]
31
+
32
+ # Sections up the handle: round waist, a first oval, the full palm swell, a shoulder, the small end face.
33
+ # Each one is a different shape; loft() skins them into one smooth body.
34
+ sections = [
35
+ Pos(0, 0, z0) * Circle(P["waist_d"] / 2),
36
+ Pos(0, 0, (z0 + zs) / 2) * Ellipse(P["swell_w"] * 0.37, P["swell_t"] * 0.40),
37
+ Pos(0, 0, zs) * Ellipse(P["swell_w"] / 2, P["swell_t"] / 2),
38
+ Pos(0, 0, (zs + L) / 2) * Ellipse(P["swell_w"] * 0.46, P["swell_t"] * 0.46),
39
+ Pos(0, 0, L) * Ellipse(P["butt_w"] / 2, P["butt_t"] / 2),
40
+ ]
41
+ grip = loft(sections)
42
+ grip = fillet(grip.edges().group_by(Axis.Z)[-1], P["dome_r"]) # dome the butt
43
+
44
+ # Front collar, rounded where the forefinger rests against it and chamfered where it meets the bed.
45
+ collar = Cylinder(P["collar_d"] / 2, z0, align=(Align.CENTER, Align.CENTER, Align.MIN))
46
+ collar = fillet(collar.edges().group_by(Axis.Z)[-1], 2.0)
47
+ collar = chamfer(collar.edges().group_by(Axis.Z)[0], 0.8)
48
+
49
+ # Tapered tang hole, open at the collar end; its narrow top closes like a cone, so it prints unsupported.
50
+ hole = Cone((P["tang_d"] + P["fit"]) / 2, (P["tang_tip_d"] + P["fit"]) / 2, P["tang_depth"],
51
+ align=(Align.CENTER, Align.CENTER, Align.MIN))
52
+ return grip + collar - hole
@@ -0,0 +1,92 @@
1
+ """One-piece desk phone stand (swan neck, leaning back, two hooks, cable opening)
2
+ Pattern: loft rounded sections of changing width along a filleted spine (waisted neck into a broad back), then add parts in a tilted Plane
3
+ Modelled on: Lamicall S1 desk phone stand (https://thegadgetflow.com/product/lamicall-s1-smartphone-dock/)
4
+ Published sizes used: 0.74 in (18.8 mm) = S1 cradle depth (press listing, URL above); iPhone 18 Pro Max 163.4 x 78.0 x 8.75 mm, 249 g (maker, https://support.apple.com/148591); iPhone Duo closed 117.8 x 84.1 x 11.3 mm, open 117.8 x 164.6 x 5.2 mm, 254 g (maker, https://support.apple.com/en-us/148588); every other size is a design choice
5
+ Concept: Holds a phone upright or sideways at a reading angle while it charges. The phone's bottom edge sits on two hooks and its back lies on a flat panel leaning 25 degrees; the charging plug hangs between the hooks and the cable leaves through the slot in the neck. The weight runs down the swan neck into the middle of a wide foot: with the tallest iPhone (163.4 mm, 249 g) upright its centre of mass lands about 45 mm in front of the heel and 60 mm behind the toe, and the 18.8 mm cradle takes the thickest (11.3 mm, 254 g) with a case. Prints as modelled, foot on the bed, no supports: the neck leans 35 degrees and the hook undersides 40 degrees from vertical. PLA or PETG, 3 walls; add stick-on rubber dots under the foot.
6
+ What makes this good: one continuous lofted spine that narrows to a neck and spreads into the back, so it reads as a designed object, not a bent plate.
7
+ """
8
+ from math import cos, radians, sin, tan
9
+
10
+ from build123d import *
11
+
12
+ P = {
13
+ "lean_deg": 25.0, # back leans this far from vertical (65 degree viewing angle)
14
+ "neck_deg": 55.0, # neck rises forward at this angle above the desk (printable overhang)
15
+ "nose_h": 26.0, # height of the bend where neck turns into back
16
+ "nose_y": -22.0, # how far forward of the origin that bend is
17
+ "bend_r": 14.0, # radius of that bend
18
+ "seat_up": 23.0, # hooks sit this far up the back from the bend corner
19
+ "back_len": 80.0, # back panel above the hooks (reaches the middle of a 163.4 mm phone)
20
+ "thick": 5.0, # spine thickness
21
+ "neck_w": 34.0, # narrowest width, at the neck (leaves 10 mm each side of the cable slot)
22
+ "back_w": 58.0, # widest width, behind the phone (phone is 78.0 wide)
23
+ "cradle": 18.8, # hook depth, front of back panel to lip (published S1 cradle)
24
+ "lip_h": 9.0, # lip height above the seat
25
+ "lip_t": 4.0, # lip and seat thickness
26
+ "hook_w": 13.0, # width of each hook
27
+ "cable_gap": 20.0, # clear gap between the hooks for the plug
28
+ "slot_len": 30.0, # cable slot through the neck, measured down the back
29
+ "foot_w": 82.0, # foot width (wider than the phone)
30
+ "foot_d": 106.0, # foot depth: toe ahead of the lip, heel behind the phone's centre of mass
31
+ "foot_y": 8.0, # foot centre, behind the origin
32
+ "foot_t": 5.0, # foot thickness
33
+ "root_fillet": 3.0, # blend of the neck into the foot
34
+ "edge_r": 1.9, # rounding on hooks and panel top (the 4 mm lip becomes a full round)
35
+ }
36
+
37
+
38
+ def build():
39
+ lean, neck, t = radians(P["lean_deg"]), radians(P["neck_deg"]), P["thick"]
40
+ up = Vector(0, sin(lean), cos(lean)) # direction up the back panel
41
+ out = Vector(0, -cos(lean), sin(lean)) # direction out of its front face, towards the phone
42
+ corner = Vector(0, P["nose_y"], P["nose_h"])
43
+ root = corner + Vector(0, 1 / tan(neck), -1) * (P["nose_h"] - P["foot_t"] / 2) # starts inside the foot
44
+ top = corner + up * (P["seat_up"] + P["back_len"])
45
+
46
+ # spine: neck up and forward from the foot, one filleted bend, then the straight leaning back
47
+ spine = Polyline(root, corner, top)
48
+ spine = fillet(spine.vertices(), P["bend_r"])
49
+
50
+ # (position along the spine 0..1, width there): flared root, narrow neck, broad back
51
+ # (the last station lies beyond the top, so the panel ends mid-curve with rounded shoulders)
52
+ stations = [(0, 48), (0.18, P["neck_w"]), (0.45, P["back_w"]), (0.8, P["back_w"]), (1.25, P["back_w"] - 40)]
53
+
54
+ def width_at(u): # smooth blend between neighbouring stations
55
+ for (u0, w0), (u1, w1) in zip(stations, stations[1:]):
56
+ if u <= u1:
57
+ k = (u - u0) / (u1 - u0)
58
+ return w0 + (w1 - w0) * (3 * k**2 - 2 * k**3)
59
+
60
+ # many evenly spaced sections keep the loft on the spine, so the panel stays flat for the phone
61
+ sections = [Plane(spine @ (i / 24), x_dir=(1, 0, 0), z_dir=spine % (i / 24))
62
+ * RectangleRounded(width_at(i / 24), t, t * 0.45) for i in range(25)]
63
+ back = loft(sections)
64
+ back = fillet(back.faces().sort_by(Axis.Z)[-1].edges(), P["edge_r"]) # soft top edge
65
+
66
+ # foot: a pebble-shaped pad, the only thing touching the bed
67
+ foot = Pos(0, P["foot_y"]) * extrude(RectangleRounded(P["foot_w"], P["foot_d"], P["foot_w"] * 0.4), P["foot_t"])
68
+ foot = fillet(foot.edges().group_by(Axis.Z)[-1], P["foot_t"] * 0.6)
69
+
70
+ # hooks, drawn in the side plane of the back: x = up the back, y = out towards the phone
71
+ seat = corner + up * P["seat_up"] + out * (t / 2)
72
+ side = Plane(seat, x_dir=up, z_dir=(1, 0, 0))
73
+ reach = P["cradle"] + P["lip_t"]
74
+ hook_profile = side * Polygon(
75
+ (0, -t / 2), (0, P["cradle"]), (P["lip_h"], P["cradle"]), (P["lip_h"], reach),
76
+ (-P["lip_t"], reach), (-P["lip_t"] - reach * tan(lean), -t / 2), align=None)
77
+ hook = extrude(hook_profile, P["hook_w"] / 2, both=True)
78
+ # round the profile first (full-round lip), then the two flanks with a smaller radius:
79
+ # equal fillets meeting at a corner make a spherical patch that does not export watertight
80
+ hook = fillet(hook.edges().filter_by(Axis.X), P["edge_r"])
81
+ hook = fillet(hook.edges().filter_by(Axis.X, reverse=True), P["edge_r"] / 2)
82
+ hook = Pos((P["cable_gap"] + P["hook_w"]) / 2, 0, 0) * hook
83
+ body = foot + back
84
+ # blend the neck into the foot: the seam is the only spline edge on the foot's top face
85
+ seam = body.edges().filter_by_position(Axis.Z, P["foot_t"] - 0.01, P["foot_t"] + 0.01).filter_by(GeomType.BSPLINE)
86
+ body = fillet(seam, P["root_fillet"])
87
+ body += hook + mirror(hook, Plane.YZ)
88
+
89
+ # cable slot through the neck between the hooks, from the seat downwards
90
+ rest = Plane(seat, x_dir=(1, 0, 0), z_dir=out)
91
+ slot = extrude(SlotOverall(P["slot_len"], P["cable_gap"] - 6, rotation=90), 2 * t, both=True)
92
+ return body - rest * Pos(0, 3 - P["slot_len"] / 2) * slot
@@ -0,0 +1,69 @@
1
+ """Under-desk headphone hook (swept arm with a broad saddle, tape or two screws)
2
+ Pattern: sweep a rounded section along a filleted Polyline path; sweep a second, wider section along part of the same path
3
+ Modelled on: ElevationLab AnchorPro under-desk headphone mount (https://www.elevationlab.com/products/the-anchor-pro); screw is SPAX 4.0 mm flat countersunk (https://www.ahlsell.se/en/products/mounting/wood-screw/wood-screw-spax/71333788---traskruv-tft-spax-svart-4.0x25h-200fp-eta-120114)
4
+ Published sizes used: 4.0 mm = screw thread diameter, 8.0 mm = head diameter, 2.4 mm = head height (retailer listing for SPAX, URL above); the maker publishes no hook dimensions, so every hook size is a design choice
5
+ Concept: Hangs a headset under the desk, out of the way. Frame: the flat top face of the plate goes against the underside of the desk (tape, or two screws driven up from below), the arm drops, runs towards -y and turns up into a tip that stops the headband sliding off; the headband enters through the 42 mm gap between tip and plate. The headband lies across the saddle, a leaf 34 mm wide with fully rounded edges so the padding is not creased the way it is on a thin wire hook. The weight bends the arm at the two bends and pulls on the plate; the bends are large-radius and the stem is filleted into the plate. Print it on its side (X up) so every layer holds the whole J and the bends are not layer joints; the plate and saddle are wider than the arm, so on its side it needs supports under the arm and saddle. PETG or PLA, 4 walls.
6
+ What makes this good: one path drives both the slim arm and the broad saddle, so the saddle follows the bends like a moulded part.
7
+ """
8
+ from build123d import *
9
+
10
+ P = {
11
+ "plate_w": 72.0, # plate across the desk edge (X); screws sit either side of the arm
12
+ "plate_d": 36.0, # plate front to back (Y); the tape area
13
+ "plate_t": 5.0, # plate thickness; leaves 2.6 mm under the screw head
14
+ "screw_d": 4.0, # screw thread diameter (published)
15
+ "screw_head_d": 8.0, # screw head diameter (published)
16
+ "screw_head_h": 2.4, # screw head height (published); sets the countersink depth
17
+ "screw_clear": 0.5, # added to thread and head diameters so the screw drops in
18
+ "screw_pitch": 50.0, # distance between the screws; clear of the saddle for the driver
19
+ "arm_w": 16.0, # arm section width (X)
20
+ "arm_t": 11.0, # arm section thickness, in the bending direction
21
+ "drop": 62.0, # plate underside down to the arm centreline
22
+ "reach": 62.0, # stem to tip, along the desk
23
+ "tip_h": 20.0, # tip rise above the arm centreline
24
+ "bend_r": 14.0, # radius of both bends
25
+ "saddle_w": 34.0, # saddle width: broad, so the headband padding is not dented
26
+ "saddle_t": 8.0, # saddle thickness; its edges are full rounds
27
+ "saddle_lift": 3.5, # saddle centre above the arm centreline, so its crown stands proud
28
+ "saddle_from": 0.38, # where the saddle starts along the path (0 = plate, 1 = tip)
29
+ "saddle_to": 0.88, # where it ends
30
+ "root_fillet": 4.0, # blend of the stem into the plate
31
+ }
32
+
33
+
34
+ def build():
35
+ z_arm = P["arm_t"] / 2 # arm centreline height; the arm's underside sits on z = 0
36
+ z_plate = z_arm + P["drop"] # plate underside
37
+ # path as 3D points: inside the plate, down the stem, along the desk, up the tip
38
+ path = Polyline((0, 0, z_plate + P["plate_t"] / 2), (0, 0, z_arm),
39
+ (0, -P["reach"], z_arm), (0, -P["reach"], z_arm + P["tip_h"]))
40
+ path = fillet(path.vertices(), P["bend_r"])
41
+
42
+ # the arm: an ellipse held square to the path at its start, swept to the tip
43
+ arm = sweep(Plane(path @ 0, x_dir=(1, 0, 0), z_dir=path % 0) * Ellipse(P["arm_w"] / 2, P["arm_t"] / 2), path=path)
44
+ tip = arm.faces().filter_by(GeomType.PLANE).sort_by(Axis.Z)[0] # the lower flat end is the tip
45
+ arm = fillet(tip.edges(), P["arm_t"] * 0.3) # rounded tip
46
+
47
+ # the saddle: a wide round-edged slot swept along the middle of the same path, lifted to the
48
+ # inside of the J (local +y of the section plane) so its top is what the headband touches
49
+ run = path.trim(P["saddle_from"], P["saddle_to"])
50
+ leaf = Plane(run @ 0, x_dir=(1, 0, 0), z_dir=run % 0) * Pos(0, P["saddle_lift"]) * SlotOverall(P["saddle_w"], P["saddle_t"])
51
+ saddle = sweep(leaf, path=run)
52
+ ends = saddle.faces().filter_by(GeomType.PLANE).edges()
53
+ saddle = fillet(ends, P["saddle_t"] * 0.35) # soft ends
54
+
55
+ # plate: flat on top for the desk, lower edge softened; stem blended in
56
+ plate = Pos(0, 0, z_plate) * extrude(RectangleRounded(P["plate_w"], P["plate_d"], P["plate_d"] * 0.4), P["plate_t"])
57
+ plate = fillet(plate.edges().group_by(Axis.Z)[0], P["plate_t"] * 0.4)
58
+ body = plate + arm
59
+ # the seam where the stem leaves the plate is the only spline edge on the plate's underside
60
+ seam = body.edges().filter_by_position(Axis.Z, z_plate - 0.01, z_plate + 0.01).filter_by(GeomType.BSPLINE)
61
+ body = fillet(seam, P["root_fillet"]) + saddle
62
+
63
+ # two countersunk holes, heads on the underside, either side of the arm
64
+ hole_r = (P["screw_d"] + P["screw_clear"]) / 2
65
+ head_r = (P["screw_head_d"] + P["screw_clear"]) / 2
66
+ screw = Cylinder(hole_r, 3 * P["plate_t"]) + Cone(head_r, hole_r, P["screw_head_h"], align=(Align.CENTER, Align.CENTER, Align.MIN))
67
+ for x in (P["screw_pitch"] / 2, -P["screw_pitch"] / 2):
68
+ body -= Pos(x, 0, z_plate) * screw
69
+ return body
@@ -0,0 +1,62 @@
1
+ """Screw-top jar and lid with a standard 70-400 neck
2
+ Pattern: revolve a wall profile for the body, sweep a thread section along a helix for the screw thread (same pitch on both parts, clearance as a radial offset), pattern a cutter round the lid for grip
3
+ Modelled on: wide-mouth jars with a GPI/SPI 70-400 continuous-thread finish (https://www.ebottles.com/blogs/articles/guide-for-fitting-closures-on-bottles)
4
+ Published sizes used: 70-400 finish, converted from the chart's inches: T (thread outside diameter) 68.61 to 69.49 mm; E (neck at the thread root) 66.22 to 67.11 mm; H (finish height) 9.98 to 10.74 mm; S (rim to thread start) 0.79 to 1.55 mm; 6 threads per inch = 4.233 mm pitch; thread depth (T - E)/2 = 1.19 mm (retailer's chart of the standard, URL above). The thread's flank angle is not in the chart: 45 degree flanks are a choice made so it prints.
5
+ Concept: A jar whose lid screws on in one turn. The neck is the standard 70-400 finish, so the printed lid also fits bought 70 mm jars and a bought cap fits this jar, give or take the printer. One turn of thread on the neck pulls the lid down until its inside face seats on the rim: the thread only holds the joint shut, the rim takes the squeeze. Both threads are the same section swept along the same helix; the lid's is moved outwards by the clearance, never scaled, so the pitch matches at every turn. The body is one revolved wall: a rounded floor corner (no stress line, easy to wipe out), a shoulder at 45 degrees so it prints without supports, a rolled rim. The lid has a domed edge and 24 finger scallops. Both print upright as modelled, jar on its floor and lid on its top face, opening up; the thread flanks are 45 degrees. PETG or PLA, 3 walls; not for food unless the filament and printer are.
6
+ What makes this good: a real standard interface, a thread made the way threads are made (one section along a helix), and every wall a single revolved curve.
7
+ """
8
+ import math
9
+ from build123d import *
10
+
11
+ P = {
12
+ "T": 69.0, # thread outside diameter (70-400: 68.61 to 69.49)
13
+ "E": 66.6, # neck diameter at the thread root (66.22 to 67.11)
14
+ "H": 10.4, # finish height, rim to shoulder (9.98 to 10.74)
15
+ "S": 1.2, # rim down to where the thread starts (0.79 to 1.55)
16
+ "pitch": 4.233, # 6 threads per inch
17
+ "turns": 1.0, # a 400 finish has one turn of thread
18
+ "crest": 1.0, # width of the thread's crest; flanks at 45 degrees from there
19
+ "body_d": 82.0, # jar body outside diameter
20
+ "body_h": 58.0, # floor to shoulder top
21
+ "wall": 2.0, # jar and lid wall
22
+ "floor": 2.4,
23
+ "corner": 8.0, # radius of the floor corner
24
+ "fit": 0.35, # radial clearance between the two threads (print allowance)
25
+ "lid_top": 2.4,
26
+ "scallops": 24, # finger scallops round the lid
27
+ "gap_on_plate": 12.0, # space between jar and lid as laid out
28
+ }
29
+
30
+ def thread(root_r, crest_r, z0):
31
+ """One thread: a 45 degree trapezoid swept along a helix. root_r may be larger than crest_r (the lid's thread)."""
32
+ depth = crest_r - root_r
33
+ half_root = P["crest"] / 2 + abs(depth) # 45 degree flanks
34
+ bury = 0.4 * (1 if depth > 0 else -1) # sink the root into the wall so the union is clean
35
+ section = Polygon((root_r - bury, -half_root - 0.4), (crest_r, -P["crest"] / 2), (crest_r, P["crest"] / 2), (root_r - bury, half_root + 0.4), align=None)
36
+ path = Helix(P["pitch"], P["pitch"] * P["turns"], (root_r + crest_r) / 2)
37
+ return Pos(0, 0, z0) * sweep(Plane.XZ * section, path=path, is_frenet=True)
38
+
39
+ def build():
40
+ w, R, top = P["wall"], P["body_d"] / 2, P["body_h"] + P["H"]
41
+ neck_r = P["E"] / 2
42
+ # jar: one closed wall section in the XZ plane, revolved; the shoulder rises at 45 degrees to the neck
43
+ shoulder_z = P["body_h"] - (R - neck_r)
44
+ outer = Polyline((0, 0), (R, 0), (R, shoulder_z), (neck_r, P["body_h"]), (neck_r, top), (neck_r - w, top),
45
+ (neck_r - w, P["body_h"] - 0.8), (R - w, shoulder_z - 0.8), (R - w, P["floor"]), (0, P["floor"]), close=True)
46
+ wall = make_face(outer)
47
+ wall = fillet(wall.vertices().filter_by_position(Axis.Y, -0.1, P["floor"] + 0.1).filter_by_position(Axis.X, R - w - 0.1, R + 0.1), P["corner"] / 2)
48
+ jar = revolve(Plane.XZ * wall, Axis.Z)
49
+ z_thread = top - P["S"] - (P["crest"] / 2 + (P["T"] - P["E"]) / 2) - P["pitch"] * P["turns"]
50
+ jar += thread(neck_r, P["T"] / 2, z_thread)
51
+
52
+ # lid: a cup over the neck, opening up as printed; its thread is the same helix moved out by the fit
53
+ lid_in = P["T"] / 2 + P["fit"]
54
+ lid_out = lid_in + w
55
+ lid_h = P["lid_top"] + P["H"] - 1.0
56
+ cup = Cylinder(lid_out, lid_h, align=(Align.CENTER, Align.CENTER, Align.MIN))
57
+ cup = fillet(cup.edges().group_by(Axis.Z)[0], 1.6) # the domed edge, on the bed
58
+ cup -= Pos(0, 0, P["lid_top"]) * Cylinder(lid_in, lid_h, align=(Align.CENTER, Align.CENTER, Align.MIN))
59
+ scallop = Pos(lid_out + 2.2, 0, 0) * Cylinder(3.0, lid_h, align=(Align.CENTER, Align.CENTER, Align.MIN))
60
+ cup -= [Rot(0, 0, i * 360 / P["scallops"]) * scallop for i in range(P["scallops"])]
61
+ lid = cup + Pos(0, 0, 0) * thread(lid_in, neck_r + P["fit"], P["lid_top"] + P["S"] + 0.6)
62
+ return Compound([jar, Pos(R + lid_out + P["gap_on_plate"], 0, 0) * lid])
@@ -0,0 +1,95 @@
1
+ """Trigger capo for a steel-string acoustic guitar
2
+ Pattern: two rigid levers on one pivot with a printed hairpin spring; each profile drawn in the plane it bends in, extruded, edges chamfered; one script gives the assembled pose and the print plate
3
+ Modelled on: Kyser Quick-Change KG6 (https://kysermusical.com/products/acoustic-guitar-capo) and Dunlop Trigger 83CB (https://www.jimdunlop.com/37083002001-trigger-capo-acoustic/)
4
+ Published sizes used: 44.45 mm = Martin D-28 fingerboard width at the nut, 53.98 mm at the 12th fret (maker, https://www.martinguitar.com/guitars/standard-series/D-28.html), so 48 mm where a capo sits; 406.4 mm (16 in) = the D-28's published saddle radius, used for the bar's curve (maker, same page; the fingerboard radius itself is not on it); 29 to 74 N = clamp force measured on bought spring capos, too little buzzes and too much pulls sharp (G7th, https://www.g7th.com/force-testing-at-sheehans); 4.5 mm = M4 clearance hole (ISO 273 medium). The neck depth (23.5 mm, string tops to the back of the neck) is not published by the maker: measure the guitar.
5
+ Concept: A capo is a spring clamp that frets all six strings at once, put on and taken off with one hand. This is the trigger kind every shop sells: two rigid levers on one pivot beside the neck. The upper lever's bar lies across the strings (curved to the fingerboard, thickest at its root where the bending is greatest) and the lower lever curls round the back of the neck to a cradle under its centre; both jaws carry a 2 mm soft pad, because bare plastic buzzes on strings and marks lacquer. Their tails are the handles: squeezing them opens the jaws, and a hairpin spring printed as part of the lower lever pushes them apart again. Load path: spring, handles, pivot screw, jaws, pads, strings and neck. The spring's two 2.94 mm legs bend in the print plane; standing 18 degrees open off the guitar it is unstrained, on the neck it gives about 34 N at the strings at about 1.5 % strain, and fully open about 2.9 % for a moment (beam estimate, PETG, E about 2000 MPa: not a measurement). Each lever prints flat on its side, so every layer runs the length of the lever and the spring; the levers are halved at the pivot (a half-lap) so both lie flat with no supports, the upper one turned over. PETG, 4 walls. Add an M4 x 20 screw with a self-locking nut, and two pads (TPU, or self-adhesive silicone strip). Take it off the guitar when you stop playing: held bent, PETG slowly relaxes.
6
+ What makes this good: it is the product (two levers, a pivot, a spring, pads, handles a hand can squeeze) with every part drawn in the plane it bends in, and it rests unstrained.
7
+ """
8
+ import math
9
+ from build123d import *
10
+
11
+ P = {
12
+ "pose": "assembled", # "assembled": clamped on the neck, standing as used; "plate": both arms flat, as printed
13
+ "neck_width": 48.0, # fingerboard width where the capo sits (frets 1 to 7)
14
+ "neck_depth": 23.5, # string tops to the back of the neck there
15
+ "board_radius": 406.4, # fingerboard radius (16 in)
16
+ "width": 16.0, # capo width along the neck = print height of each arm
17
+ "pad": 2.0, # soft pad on both jaws (TPU, or a bought silicone strip)
18
+ "bar_tip": 6.0, # string bar thickness at its free end
19
+ "bar_root": 10.0, # and at its root, where the bending moment is greatest
20
+ "arm": 8.0, # thickness of the neck arm and the handles
21
+ "pivot_out": 17.0, # pivot centre: this far outside the bass edge of the fingerboard
22
+ "pivot_down": 9.0, # and this far below the string tops
23
+ "pivot_d": 4.5, # clearance hole for an M4 screw (ISO 273, medium)
24
+ "lug_r": 8.0, # pivot lug radius
25
+ "handle": 54.0, # handle length from the pivot
26
+ "handle_deg": 30.0, # each handle's angle from the horizontal, clamped
27
+ "spring_t": 2.94, # hairpin leg thickness: 7 lines of 0.42
28
+ "spring_set": 18.0, # degrees the free spring stands open beyond its seat: gives the clamp force
29
+ "edge": 1.2, # chamfer on every long edge a hand or the guitar touches
30
+ "gap": 0.3, # clearance between the arms at the pivot, and under each pad
31
+ }
32
+
33
+ def polar(c, r, deg):
34
+ return (c[0] + r * math.cos(math.radians(deg)), c[1] + r * math.sin(math.radians(deg)))
35
+
36
+ def stroke(curve, w): # a curve given width, with round ends
37
+ return trace(curve, w) + Pos((curve @ 0).X, (curve @ 0).Y) * Circle(w / 2) + Pos((curve @ 1).X, (curve @ 1).Y) * Circle(w / 2)
38
+
39
+ def build():
40
+ W, pad, half, arm, H, g = P["neck_width"], P["pad"], P["neck_width"] / 2, P["arm"], P["width"], P["gap"]
41
+ piv = (W + P["pivot_out"], -P["pivot_down"])
42
+ sag = P["board_radius"] - math.sqrt(P["board_radius"] ** 2 - half ** 2) # the fingerboard's crown
43
+ lug = Pos(*piv) * Circle(P["lug_r"])
44
+
45
+ # upper arm: string bar (thickest at its root), shoulder down to the pivot, handle up and out
46
+ x0, x1 = -3.0, W + 3.0
47
+ under = ThreePointArc((x0, pad - sag), (half, pad), (x1, pad - sag)) # follows the fingerboard radius
48
+ over = Spline((x1, pad + P["bar_root"]), (half, pad + (P["bar_tip"] + P["bar_root"]) / 2 + 0.8), (x0, pad + P["bar_tip"]))
49
+ bar = make_face([under, Line(under @ 1, over @ 0), over, Line(over @ 1, under @ 0)])
50
+ bar = fillet(bar.vertices().sort_by(Axis.X)[:2], 2.5) # round the free tip
51
+ shoulder = stroke(Spline((x1 - 5, pad + P["bar_root"] / 2), (x1 + 5, pad + 2), piv), P["bar_root"])
52
+ up_tip = polar(piv, P["handle"], P["handle_deg"])
53
+ upper = bar + shoulder + lug + stroke(Spline(piv, polar(piv, P["handle"] * 0.5, P["handle_deg"] + 6), up_tip), arm) + Pos(*up_tip) * Circle(arm * 0.8)
54
+
55
+ # lower arm: an elliptical C round the back of the neck to a cradle under its centre, handle down and out
56
+ cx, cy = half, -2.5
57
+ a, b = half + 3.0 + arm / 2, P["neck_depth"] + cy + pad + arm / 2 # the C's centre line
58
+ ell = lambda t, da=0.0: (cx + (a + da) * math.cos(math.radians(t)), cy + (b + da) * math.sin(math.radians(t)))
59
+ lo_tip = polar(piv, P["handle"], -P["handle_deg"])
60
+ lower = stroke(Spline(piv, *[ell(t) for t in range(-30, -119, -11)]), arm) + lug
61
+ lower += stroke(Spline(piv, polar(piv, P["handle"] * 0.5, -P["handle_deg"] - 6), lo_tip), arm) + Pos(*lo_tip) * Circle(arm * 0.8)
62
+
63
+ # hairpin spring, part of the lower arm, in the wedge between the handles: from the lower handle's tip in
64
+ # towards the pivot, round a bend, and out to bear under the upper handle. Both legs bend in the print plane.
65
+ t, rb = P["spring_t"], 6.0
66
+ bend = polar(piv, 28.0, 0)
67
+ seat_deg = P["handle_deg"] - math.degrees(math.asin((arm / 2 + t / 2 + g) / (P["handle"] - 8)))
68
+ open_deg = P["spring_set"] if P["pose"] == "plate" else 0.0 # free shape on the plate, seated when assembled
69
+ root = polar(piv, P["handle"] - 2, -P["handle_deg"] + 4)
70
+ nose = polar(piv, P["handle"] - 8, seat_deg + open_deg)
71
+ lo_b, up_b = polar(bend, rb, -90), polar(bend, rb, 90 + open_deg)
72
+ hairpin = stroke(Line(root, lo_b), t) + stroke(ThreePointArc(lo_b, polar(bend, rb, 180 + open_deg / 2), up_b), t) + stroke(Line(up_b, nose), t)
73
+
74
+ # solids: extrude, round the long edges, then halve each arm at the pivot (a half-lap) so both print flat
75
+ hole = Pos(*piv) * Circle(P["pivot_d"] / 2)
76
+ lap = Pos(*piv) * Circle(P["lug_r"] + 5.0)
77
+ def solid(sketch, keep_low, spring=None):
78
+ body = extrude(sketch - hole, H)
79
+ # break both faces' edges with a chamfer: on an outline built from many curves a chamfer always succeeds
80
+ # where OCCT's fillet often fails, and on the bed face it also takes up the first layer's flare
81
+ body = chamfer(body.edges().group_by(Axis.Z)[0] + body.edges().group_by(Axis.Z)[-1], P["edge"])
82
+ if spring: # the spring keeps square edges: it is thinner than two chamfers
83
+ body += extrude(spring, H)
84
+ cut = extrude(lap, H / 2 + g / 2 + 1)
85
+ return body - (Pos(0, 0, H / 2 - g / 2) * cut if keep_low else Pos(0, 0, -1) * cut)
86
+ upper3, lower3 = solid(upper, False), solid(lower, True, hairpin)
87
+
88
+ if P["pose"] == "plate": # as printed: each arm on its side, the upper one turned over so its half-lap is on the bed
89
+ return Compound([lower3, Pos(0, 50, H) * Rot(180, 0, 0) * upper3])
90
+ # soft pads, shown in place: under the bar on the strings, and in the cradle on the back of the neck
91
+ string_pad = make_face([ThreePointArc((x0 + 1, -sag), (half, 0), (x1 - 1, -sag)), Line((x1 - 1, -sag), (x1 - 1, pad - sag - g)),
92
+ ThreePointArc((x1 - 1, pad - sag - g), (half, pad - g), (x0 + 1, pad - sag - g)), Line((x0 + 1, pad - sag - g), (x0 + 1, -sag))])
93
+ neck_pad = trace(Spline(*[ell(t, -arm / 2 - pad / 2 - g) for t in range(-112, -67, 11)]), pad)
94
+ pads = [Pos(0, 0, 1) * extrude(s, H - 2) for s in (string_pad, neck_pad)]
95
+ return Pos(0, 0, 40) * Rot(90, 0, 0) * Compound([upper3, lower3, *pads]) # stand it up: the neck runs along Y
@@ -0,0 +1,65 @@
1
+ """Screw-on wall coat hook (single curved arm with a ball tip)
2
+ Pattern: loft elliptical sections placed along a spline (an arm that tapers), ball tip, fillet the arm into the back plate
3
+ Modelled on: classic cast single coat hook; screw is SPAX 4.0 mm flat countersunk (https://www.ahlsell.se/en/products/mounting/wood-screw/wood-screw-spax/71333788---traskruv-tft-spax-svart-4.0x25h-200fp-eta-120114)
4
+ Published sizes used: 4.0 mm = screw thread diameter, 8.0 mm = head diameter, 2.4 mm = head height (retailer listing for SPAX, URL above); plate and arm sizes are design choices (no hook maker publishes them)
5
+ Concept: A coat hook for one heavy coat or bag. Frame: the wall is the XZ plane at y = 0, the hook reaches towards -y (towards the front view), Z is up. The coat's weight bends the arm like a cantilever, so the arm is deepest (in Z) where it meets the plate and thins towards the tip; the root is filleted so the stress does not peak at a sharp corner; the plate turns that bending into a pull on the top screw and a push on the wall at the bottom. The ball tip is fatter than the arm so a loop cannot slide off. Print it lying on its side (X up, one flank of the plate on the bed) so every layer contains the whole curve of the arm: printed plate-down, the arm would snap along a layer at the root. On its side the arm floats a few mm above the bed, so it needs supports under the arm and a brim. PETG or PLA, 4 walls.
6
+ What makes this good: the arm is a tapering loft along a curve with a filleted root and ball tip, like a cast hook, not a bent strip.
7
+ """
8
+ from build123d import *
9
+
10
+ P = {
11
+ "plate_w": 30.0, # back plate width (X)
12
+ "plate_h": 96.0, # back plate height (Z)
13
+ "plate_t": 6.0, # back plate thickness (Y); leaves 3.6 mm under the screw head
14
+ "plate_edge_r": 2.0, # soft front edge of the plate
15
+ "screw_d": 4.0, # screw thread diameter (published)
16
+ "screw_head_d": 8.0, # screw head diameter (published)
17
+ "screw_head_h": 2.4, # screw head height (published); sets the countersink depth
18
+ "screw_clear": 0.5, # added to thread and head diameters so the screw drops in
19
+ "screw_pitch": 68.0, # distance between the two screws, one above and one below the arm
20
+ "reach": 46.0, # how far the tip stands off the plate face
21
+ "dip": 9.0, # how far the arm sags below its root before turning up (the coat sits here)
22
+ "rise": 15.0, # tip height above the root
23
+ "root_w": 15.0, # arm width (X) at the plate
24
+ "root_h": 21.0, # arm depth (Z) at the plate: deep where the bending is highest
25
+ "tip_d": 10.0, # arm diameter just under the ball
26
+ "ball_d": 14.0, # ball tip diameter
27
+ "root_fillet": 4.0, # blend of the arm into the plate
28
+ }
29
+
30
+
31
+ def build():
32
+ t = P["plate_t"]
33
+ # back plate: a slot outline (round ends) pulled off the wall, front edge softened
34
+ plate = extrude(Plane.XZ * SlotOverall(P["plate_h"], P["plate_w"], rotation=90), t)
35
+ plate = fillet(plate.edges().group_by(Axis.Y)[0], P["plate_edge_r"])
36
+
37
+ # arm centreline in the YZ plane: leaves the plate square (so the root section stays
38
+ # inside the plate), dips, then turns up to the tip
39
+ spine = Spline(
40
+ [(0, -1, 0), (0, -t - 0.5 * P["reach"], -P["dip"]), (0, -t - P["reach"], P["rise"])],
41
+ tangents=[(0, -1, 0), (0, 0, 1)],
42
+ )
43
+ # ellipses square to the spine: deep and wide at the root, round at the tip
44
+ sections = []
45
+ for i in range(5):
46
+ u = i / 4
47
+ w = P["root_w"] + (P["tip_d"] - P["root_w"]) * u**0.6
48
+ h = P["root_h"] + (P["tip_d"] - P["root_h"]) * u**0.6
49
+ sections.append(Plane(spine @ u, x_dir=(1, 0, 0), z_dir=spine % u) * Ellipse(w / 2, h / 2))
50
+ # ball tip; trimming 0.05 mm off the sphere's poles keeps the exported mesh watertight
51
+ ball = Sphere(P["ball_d"] / 2) & Box(P["ball_d"], P["ball_d"], P["ball_d"] - 0.1)
52
+ arm = loft(sections) + Pos(spine @ 1) * ball
53
+
54
+ body = plate + arm
55
+ # the seam where the arm meets the plate face is the only spline edge on that face
56
+ seam = body.edges().filter_by_position(Axis.Y, -t - 0.01, -t + 0.01).filter_by(GeomType.BSPLINE)
57
+ body = fillet(seam, P["root_fillet"])
58
+
59
+ # two countersunk screw holes through the plate, heads flush with the front face
60
+ hole_r = (P["screw_d"] + P["screw_clear"]) / 2
61
+ head_r = (P["screw_head_d"] + P["screw_clear"]) / 2
62
+ screw = Cylinder(hole_r, 3 * t) + Cone(hole_r, head_r, P["screw_head_h"], align=(Align.CENTER, Align.CENTER, Align.MAX))
63
+ for z in (P["screw_pitch"] / 2, -P["screw_pitch"] / 2):
64
+ body -= Pos(0, -t, z) * Rot(90, 0, 0) * screw
65
+ return body
@@ -0,0 +1,77 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ /**
6
+ * The code engine's cookbook: worked build123d designs, each modelled on the best bought version of the thing, kept as
7
+ * plain scripts in src/cad/examples/. A design worker reaches them only through this MCP: the cad_design prompt names
8
+ * each pattern in one line, and the read-only cad_examples tool returns one script on request, so the prompt pays a
9
+ * line per example instead of a script per example.
10
+ *
11
+ * A script's header (its docstring) is the record: title on the first line, then "Pattern:", "Modelled on:",
12
+ * "Published sizes used:", "Concept:" and "What makes this good:".
13
+ */
14
+ const DIR = fileURLToPath(new URL("../../src/cad/examples/", import.meta.url));
15
+ const FIELDS = {
16
+ "Pattern": "pattern",
17
+ "Modelled on": "modelled_on",
18
+ "Published sizes used": "published_sizes",
19
+ "Concept": "concept",
20
+ "What makes this good": "what_makes_this_good",
21
+ } as const;
22
+ type Field = (typeof FIELDS)[keyof typeof FIELDS];
23
+ export type CadExample = { name: string; title: string; script: string } & Record<Field, string>;
24
+
25
+ /** Simplest first: the order the list and the prompt present them in. */
26
+ export const CAD_EXAMPLE_ORDER = [
27
+ "cable_clip", "wall_hook", "knurled_knob", "phone_stand", "swept_hook", "loft_handle", "threaded_jar",
28
+ "bag_clip", "hinged_box", "bistable_clicker", "chainmail", "trigger_capo",
29
+ ];
30
+
31
+ function parse(name: string, script: string): CadExample {
32
+ const header = /^\s*"""([\s\S]*?)"""/.exec(script)?.[1] ?? "";
33
+ const lines = header.split("\n");
34
+ const example = { name, title: (lines.shift() ?? name).trim(), script } as CadExample;
35
+ let field: Field | undefined;
36
+ for (const line of lines) {
37
+ const start = /^([A-Z][A-Za-z ]+):\s*(.*)$/.exec(line);
38
+ const key = start && (FIELDS as Record<string, Field>)[start[1]];
39
+ if (start && key) { field = key; example[key] = start[2].trim(); }
40
+ else if (field && line.trim()) example[field] += " " + line.trim();
41
+ }
42
+ for (const key of Object.values(FIELDS)) example[key] ??= "";
43
+ return example;
44
+ }
45
+
46
+ let cache: CadExample[] | undefined;
47
+ /** Every example on disk, in cookbook order (unlisted files last, by name). Empty when the folder is missing. */
48
+ export function cadExamples(): CadExample[] {
49
+ if (cache) return cache;
50
+ let files: string[] = [];
51
+ try { files = fs.readdirSync(DIR).filter((f) => /^[a-z0-9_]+\.py$/.test(f)); } catch { /* no cookbook shipped */ }
52
+ const rank = (n: string) => { const i = CAD_EXAMPLE_ORDER.indexOf(n); return i < 0 ? CAD_EXAMPLE_ORDER.length : i; };
53
+ cache = files.map((f) => parse(f.slice(0, -3), fs.readFileSync(path.join(DIR, f), "utf8")))
54
+ .sort((a, b) => rank(a.name) - rank(b.name) || a.name.localeCompare(b.name));
55
+ return cache;
56
+ }
57
+
58
+ /** One line per example for the cad_design prompt: "name: what it is; the pattern it shows". */
59
+ export function cadExampleLines(): string {
60
+ return cadExamples().map((e) => `${e.name}: ${e.title}; ${e.pattern}`).join("\n");
61
+ }
62
+
63
+ /** cad_examples: without a name, the list; with one, that example's record and script. */
64
+ export function cadExamplesTool(args: Record<string, unknown>): Record<string, unknown> {
65
+ const extra = Object.keys(args).filter((k) => k !== "name");
66
+ if (extra.length) throw new Error("cad_examples accepts only name.");
67
+ const all = cadExamples();
68
+ if (args.name === undefined)
69
+ return {
70
+ examples: all.map(({ name, title, pattern, modelled_on }) => ({ name, title, pattern, modelled_on })),
71
+ usage: "Call cad_examples with one name to read its concept and script. Adapt the pattern to the request and to the product the person means; do not paste an example's sizes onto a different object.",
72
+ };
73
+ if (typeof args.name !== "string") throw new Error("name must be a string.");
74
+ const found = all.find((e) => e.name === args.name);
75
+ if (!found) throw new Error(`No example named ${JSON.stringify(args.name)}. Examples: ${all.map((e) => e.name).join(", ")}.`);
76
+ return { ...found };
77
+ }