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.
@@ -1,4 +1,5 @@
1
1
  import { CAD_REFUSAL_CODES } from "./refusal.js";
2
+ import { cadExampleLines } from "./examples.js";
2
3
  /** cad/1 is an optional engine owned by the printer MCP. Readiness comes from cad_status, not the capability. */
3
4
  export function cadEnabled(env: NodeJS.ProcessEnv = process.env): boolean {
4
5
  return !["0", "false", "off"].includes(
@@ -11,6 +12,7 @@ export const CAD_CAPABILITY = {
11
12
  setup: "cad_setup",
12
13
  run: "cad_run",
13
14
  checkFit: "cad_check_fit",
15
+ examples: "cad_examples",
14
16
  prompt: "cad_design",
15
17
  } as const;
16
18
  const storage = {
@@ -37,6 +39,7 @@ const status = {
37
39
  build123d: { type: "string" },
38
40
  platform: { type: "string" },
39
41
  error: { type: "string" },
42
+ reverified: { type: "string" },
40
43
  };
41
44
  const failure = {
42
45
  type: "object",
@@ -66,7 +69,7 @@ export const CAD_TOOLS = [
66
69
  {
67
70
  name: "cad_status",
68
71
  description:
69
- "Read the optional code-CAD runtime's last verified readiness and pinned version, without starting Python or installing anything.",
72
+ "Read the optional code-CAD runtime's readiness and pinned version. Never installs or downloads anything. When only this MCP's own engine files changed since the runtime was last verified (an update) and the installed runtime still matches the pinned lock exactly, it re-runs setup's confined build, STL and STEP round trip (about 15 to 20 seconds) and reports ready; a changed runtime still needs cad_setup with install: true.",
70
73
  inputSchema: {
71
74
  type: "object" as const,
72
75
  properties: {},
@@ -110,7 +113,7 @@ export const CAD_TOOLS = [
110
113
  {
111
114
  name: "cad_run",
112
115
  description:
113
- "Build parametric CAD headlessly in OS confinement. Read cad_design first: declare literal P = {...} and build() returning a build123d Shape. Supply script OR script_path; parameters overrides saved named values in one call before derived dimensions. Calls wait for the environment’s exclusive execution slot up to their own deadline and report queue_wait_ms. Each call creates a private immutable subfolder under allowed output_dir, never overwriting previous artifacts. The saved .py and .parameters.json are the recovery checkpoint even after cancellation. Returns independently measured geometry, STL/STEP, six renders and a contact sheet, the closest approach between every pair of solids (bodies), problems, and what was checked and not checked; valid means only that the exported geometry is sound, never that the part fits, holds, moves or prints.",
116
+ "Build parametric CAD headlessly in OS confinement. Read cad_design first: declare literal P = {...} and build() returning a build123d Shape. Supply script OR script_path; parameters overrides saved named values in one call before derived dimensions. Calls wait for the environment’s exclusive execution slot up to their own deadline and report queue_wait_ms. Each call creates a private immutable subfolder under allowed output_dir, never overwriting previous artifacts. The saved .py and .parameters.json are the recovery checkpoint even after cancellation. Returns independently measured geometry, STL/STEP, six orthographic renders, a perspective view and a contact sheet, the closest approach between every pair of solids (bodies), problems, and what was checked and not checked; valid means only that the exported geometry is sound, never that the part fits, holds, moves or prints.",
114
117
  inputSchema: {
115
118
  type: "object" as const,
116
119
  properties: {
@@ -245,6 +248,48 @@ export const CAD_TOOLS = [
245
248
  ],
246
249
  ),
247
250
  },
251
+ {
252
+ name: "cad_examples",
253
+ description:
254
+ "The code engine's cookbook: worked build123d designs from simple to complex, each modelled on the best bought version of the thing, with its concept, published sizes and script. Without arguments, lists them (name, title, the pattern each shows, the product it is modelled on). With name, returns that example's record and full script to adapt. Read-only; starts no process.",
255
+ inputSchema: {
256
+ type: "object" as const,
257
+ properties: {
258
+ name: {
259
+ type: "string",
260
+ description: "An example's name from the list; omit to list them.",
261
+ },
262
+ },
263
+ additionalProperties: false,
264
+ },
265
+ outputSchema: output(
266
+ {
267
+ examples: {
268
+ type: "array",
269
+ items: {
270
+ type: "object",
271
+ properties: {
272
+ name: { type: "string" },
273
+ title: { type: "string" },
274
+ pattern: { type: "string" },
275
+ modelled_on: { type: "string" },
276
+ },
277
+ required: ["name", "title", "pattern"],
278
+ },
279
+ },
280
+ usage: { type: "string" },
281
+ name: { type: "string" },
282
+ title: { type: "string" },
283
+ pattern: { type: "string" },
284
+ modelled_on: { type: "string" },
285
+ published_sizes: { type: "string" },
286
+ concept: { type: "string" },
287
+ what_makes_this_good: { type: "string" },
288
+ script: { type: "string" },
289
+ },
290
+ [],
291
+ ),
292
+ },
248
293
  {
249
294
  name: "cad_check_fit",
250
295
  description:
@@ -320,14 +365,18 @@ export const CAD_DESIGN_PROMPT = {
320
365
  description:
321
366
  "MCP-owned rules for headless build123d designs and one-call parameter revisions.",
322
367
  text: `Use code-CAD for dimensioned functional designs and parameter edits. Build in millimetres with build123d 0.13.0; the MCP owns the Python environment, execution, export, validation and rendering. Check cad_status and use cad_setup with install: true when needed. No Blender, Fusion, network or printer access is available to your script.
323
- Declare exactly one top-level P = {...} dictionary of JSON-compatible literal named parameters. Put every functional dimension in P; derive geometry from P. Define build() to return a build123d Shape or Compound of disjoint solid parts. When a design has separate bodies (print-in-place parts, a captive wheel, links of a fabric), return Compound(children=[...]) with a label on each body: cad_run then checks that each labelled body is exactly one solid, so a piece cut off one body cannot hide behind two bodies fused into one. Near pairs of solids are screened and, where the screen cannot clear them, measured exactly against P["print_in_place_clearance_mm"] when you declare it, else 0.3 mm. If the bodies are shown assembled rather than printed in place (a shaft in its hole at a fit clearance), set P["print_in_place"] = False: only touching or overlap is then a problem. Export in print orientation with the plate at Z = 0: a solid below it, or above it with nothing under it that reaches it, is a problem. Do not put construction or exports in a __main__ block: cad_run calls build() and exports the result. Imports, functions and derived P entries are fine. Parameters are applied to the literal defaults before derived expressions execute. For solid designs without inputs, the script and parameters file alone reconstruct it. For input-dependent designs, declare inputs as an array of {name, path} files: cad_run snapshots only those allowed files, exposes INPUTS[alias] to your script, and saves an inputs manifest. Retain the snapshots too for recovery; subsequent script_path edits reuse them unless inputs is explicitly supplied. No other personal files are readable. For a mesh-only experiment use mode: "mesh" and return a trimesh.Trimesh from build(); it exports and checks STL plus six renders, with step: null and an explicit reason. It does not manufacture a fake parametric STEP or promise scan-cleanup capability.
368
+ Form first: build the product's shape, not a profile pushed up. Before any geometry, write the concept in a few lines: the bought product you are following, its mechanism, the load path, the print orientation and why. build123d has loft (through sections of different shape), sweep (a section along a path or a Helix), revolve, fillet, chamfer, offset and shell as well as extrude; use the one the product's surface calls for: lofted where a hand closes round it, revolved where it turns, swept where it runs like a bent rod or a thread, filleted where two surfaces meet under load. Extrude a flat profile only for something that really is a plate or a lever, or for a print-in-place mechanism or spring that must lie in the layers, and say that reason in the result. Choose the print orientation after the form: split a part, turn it or accept a modest support before flattening its design.
369
+ Worked examples: cad_examples lists this engine's cookbook (each modelled on a bought product, with its concept, published sizes and script) and returns one script by name. When the request works like one of these, read that example first and adapt its pattern, never its sizes:
370
+ ${cadExampleLines()}
371
+ What the cookbook taught about this engine: return several bodies as Compound([a, b]); bodies that touch or overlap come back invalid, so leave a real gap (0.2 mm or more) or union them, and check that solid_count equals the bodies you intend (for a print-in-place mechanism that count is the first evidence nothing fused). fillet() often fails on the edges of an outline unioned from many curves, where chamfer() usually succeeds: fillet or chamfer simple bodies before the booleans that complicate them, and when a chamfer fails too, apply it to the plain body and union the details on afterwards. Do not round a sketch by growing and shrinking it with offset(): the solid looks right and its STEP comes back with no solids (the step_solids check fails). A whole Sphere() exports open at its poles: trim them (Sphere(r) & Box(2 * r, 2 * r, 2 * r - 0.1)). One fillet of the same radius over every edge of a box can export open: fillet in two passes with different radii. A model with moving parts takes a pose parameter: the assembled pose to judge it, the print plate to make it.
372
+ Declare exactly one top-level P = {...} dictionary of JSON-compatible literal named parameters. Put every functional dimension in P; derive geometry from P. Define build() to return a build123d Shape or Compound of disjoint solid parts. When a design has separate bodies (print-in-place parts, a captive wheel, links of a fabric), return Compound(children=[...]) with a label on each body: cad_run then checks that each labelled body is exactly one solid, so a piece cut off one body cannot hide behind two bodies fused into one. Near pairs of solids are screened and, where the screen cannot clear them, measured exactly against P["print_in_place_clearance_mm"] when you declare it, else 0.3 mm. If the bodies are shown assembled rather than printed in place (a shaft in its hole at a fit clearance), set P["print_in_place"] = False: only touching or overlap is then a problem. Export in print orientation with the plate at Z = 0: a solid below it, or above it with nothing under it that reaches it, is a problem. Do not put construction or exports in a __main__ block: cad_run calls build() and exports the result. Imports, functions and derived P entries are fine. Parameters are applied to the literal defaults before derived expressions execute. For solid designs without inputs, the script and parameters file alone reconstruct it. For input-dependent designs, declare inputs as an array of {name, path} files: cad_run snapshots only those allowed files, exposes INPUTS[alias] to your script, and saves an inputs manifest. Retain the snapshots too for recovery; subsequent script_path edits reuse them unless inputs is explicitly supplied. No other personal files are readable. For a mesh-only experiment use mode: "mesh" and return a trimesh.Trimesh from build(); it exports and checks STL plus the same renders, with step: null and an explicit reason. It does not manufacture a fake parametric STEP or promise scan-cleanup capability.
324
373
  Call cad_run with script, output_dir and a plain name. It saves <name>.py and <name>.parameters.json before running, then exports <name>.stl and <name>.step in a fresh subfolder. For an edit, one cad_run with script_path pointing to the earlier .py, parameters containing just the changed dimension, output_dir and name regenerates it without resending the script. Existing parameter values are retained; unknown names and type changes are refused. A killed run can be retried from its checkpoint in a new workspace; mutations are never replayed automatically.
325
374
  Captured mesh preparation: load_scan(name, source_units="m" or "mm", up_axis="x"|"-x"|"y"|"-y"|"z"|"-z", ground=True) is provided to build(). Name must be a declared input. Declare source units and the object's usage-up axis explicitly: the helper converts metres to millimetres, applies a rigid up-axis rotation and translates the lowest Z to zero; it never guesses scale or fits to calipers. Geometry/texture references must be declared inputs too; snapshots preserve distinct original filenames. Exports must be millimetres, Z up, in the orientation the object is used.
326
375
  Fit reference workflow: return load_scan("scan", source_units="m", up_axis="y") from build() in mode: "mesh" to export an unchanged, prepared reference STL for cad_check_fit. Declare every linked OBJ/MTL/texture asset. If you crop, simplify, fill, or otherwise alter this reference, report exactly what you excluded/changed and that the fit check proves only that reduced reference in the stated pose. A fit check against a scan is information; it must never resize or override an interface specified by measured dimensions. Keep those measured interfaces and report the discrepancy.
327
376
  Result selection and edits: set final: true only on the result you select. cad-result.json in each immediate run folder is protected from script writes and retains final, completed_at, lineage_id (source hash), full checks and artifact paths; clients can discover the latest completed final record after restart without rebuilding. Final is a selection marker, not a replacement for valid/checks. Queued calls may expire with cad-queue-timeout before dispatch; do not automatically replay. Unchanged declared files reuse a read-only content-addressed bundle under output_dir/.cad-inputs, preserving filenames and restricting reads to that bundle. Keep this shared cache with the saved runs.
328
377
  Mesh cleanup workflow: return a trimesh.Trimesh in mode: "mesh". Load the prepared mesh, fit needed geometry with NumPy/SciPy, rebuild regular sections/features with build123d or manifold3d CrossSection/extrusion/revolve, and combine meshes with manifold3d booleans. scikit-image supplies marching cubes for voxel/SDF work; Shapely supplies planar operations; Pillow supplies image/texture reads. Keep numeric choices in P and regenerate from declared inputs. Validate closure, winding, manifold status, dimensions and all six views using cad_run. What to regularise, infer, preserve or label comes from the caller's cleanup rules, not this engine prompt.
329
378
  Captured scan touch-up: t = scan_touchup(load_scan("scan", source_units="m", up_axis="y", ground=False), colour="colour", normal="normal", edge_mm=0.4) takes a textured capture (declare its OBJ, MTL and colour and normal map PNGs as inputs; pass the map aliases). It removes loose pieces and spikes, closes holes and refines to edge_mm without shrinking the body. t.regions() prints the colour regions (id, colour, area, size, flatness; 0 is the body) to build.log and saves regions.png in the run folder: read both, then name regions by id in the same scan and edge_mm. t.flatten(ids, shape="plane" or "curved"), t.bead(id, diameter_mm, proud_mm), t.cord(id, diameter_mm, proud_mm) (a cord follows its region's own curve) and t.seat(height_mm) record steps; return t.mesh(relief_gain=1.0), which adds the normal map's measured relief, applies the steps with manifold3d and prints its changes. Keep relief_gain at 1: a larger gain amplifies the map's noise, not stitches. When the caller's rules call for a textile's relief the scan missed (fabric, knit, crochet the photos show raised), t.texture_relief(height_mm, regions=None) raises its stitch pattern from the colour texture on the textile only (never flattened, beaded or corded regions); about 0.6 to 1.0 mm peak to peak prints visibly. It is off unless called: never for hard objects, printed graphics or labels.
330
- The result includes paths, millimetre bounds/size, mesh and STEP volumes, solid count, watertight/manifold/winding/STEP checks, bodies (closest approach between solids, contact with the print plate at Z = 0, labelled bodies that are not one solid), problems, checked and not_checked, six orthographic renders (front, back, left, right, top, bottom) and contact sheet. Fix every entry in problems before selecting a result; an empty problems list proves nothing listed in not_checked. Inspect all six; revise visible defects. A valid mesh or nominal parameter does not prove the requested dimension: measure the actual exported interfaces. Use cad_check_fit on a model and reference STL with an explicit rigid transform; report raw-scan interference and minimum gap. Calipers are authoritative but disagreement with a scan is unresolved measurement evidence, not permission to silently rescale it. Check assembly/insertion paths and actual articulated poses, not sums of local joint limits or reference points alone. Printing, clearance under load, supports and motion need separate evidence.
379
+ The result includes paths, millimetre bounds/size, mesh and STEP volumes, solid count, watertight/manifold/winding/STEP checks, bodies (closest approach between solids, contact with the print plate at Z = 0, labelled bodies that are not one solid), problems, checked and not_checked, six orthographic renders (front, back, left, right, top, bottom), a perspective view from the front right and above, and a contact sheet with the perspective view large beside the six. Fix every entry in problems before selecting a result; an empty problems list proves nothing listed in not_checked. Judge the form from the perspective view first: would a person recognise the product and want it? Then inspect all six; revise visible defects. A valid mesh or nominal parameter does not prove the requested dimension: measure the actual exported interfaces. Use cad_check_fit on a model and reference STL with an explicit rigid transform; report raw-scan interference and minimum gap. Calipers are authoritative but disagreement with a scan is unresolved measurement evidence, not permission to silently rescale it. Check assembly/insertion paths and actual articulated poses, not sums of local joint limits or reference points alone. Printing, clearance under load, supports and motion need separate evidence.
331
380
  Fit, flexure and thread parameters: put each interface's nominal size, its source (measured, published, or assumed), the print correction, and the design fit in P as separate named values, so a fit report revises one number without resending the script. Model every dimension you claim: a parameter the geometry never uses (a wallet or case width that no cut or wall reads) is a defect; use it or remove it. Shape flexures so their bending lies in the layer plane of the exported print orientation, with the stroke, preload, and hard-stop gap as P values; build the stopped pose as well as the rest pose when checking. Model printed threads as explicit coarse geometry with the same pitch on both sides and clearance as a radial P offset; never scale a screw to clear its hole.
332
- Check insertion and articulated poses with cad_check_fit against each object state that matters (the bare product, the product in its case, and the case with its attachment as its own reference envelope), including the widest section on the way in. Report interference and minimum gap per state. In your summary, attach each "fits", "holds", and "prints without supports" claim to the check or slice number that shows it; a valid flag alone shows none of them. Apply fdm_design and fdm_slicing too, with fdm_fit and fdm_flexures when they apply; never invoke a printer as part of constructing CAD.`,
381
+ Check insertion and articulated poses with cad_check_fit against each object state that matters (the bare product, the product in its case, and the case with its attachment as its own reference envelope), including the widest section on the way in. Report interference and minimum gap per state. In your summary, attach each "fits", "holds", and "prints without supports" claim to the check or slice number that shows it; a valid flag alone shows none of them. Apply fdm_design and fdm_slicing too. When a part meets a real object apply fdm_fit, and when it flexes, grips, snaps or springs apply fdm_flexures: if they were not attached, read them with the design_guidance tool before choosing that fit or spring. Never invoke a printer as part of constructing CAD.`,
333
382
  };
@@ -0,0 +1,86 @@
1
+ """Bag-sealing clip: two hinged bars, ridge into groove, snap latch, printed in place
2
+ Pattern: bar cross-section drawn in YZ and extruded along the bar; revolved waisted pin in a C-socket; ridge and its offset as the groove; modelled SHUT, then one bar swung open for printing
3
+ Modelled on: Linden Sweden Twixit! bag clip (https://www.webstaurantstore.com/linden-sweden-411-8-twixit-blue-4-1-4-pastry-bag-clips-pack/534411.8.html); mechanism as in the hinged-bar clip patent US 4656697, Naslund (https://patents.google.com/patent/US4656697)
4
+ Published sizes used: 108 mm (4 1/4 in) = overall length (retailer, https://www.webstaurantstore.com/linden-sweden-411-8-twixit-blue-4-1-4-pastry-bag-clips-pack/534411.8.html); nothing else is published, the other sizes are design choices
5
+ Concept: Closes an opened bag of coffee, crisps or frozen peas. Two bars are hinged at one end and latched at the other; a ridge along one bar pushes the bag film into a groove along the other, so the film is pinched on both flanks of the ridge for the whole length, which is what seals it (the bought clip does the same with two thin legs in a wedge channel). 2 bodies: bar A carries the ridge, the hinge pin on a neck, the yoke round the socket and the latch arm; bar B carries the groove and a C-shaped socket. The bag pushes the bars apart: at the hinge that load goes from the socket's closed side into the pin (the socket's opening faces backwards, away from the load), at the other end from B's back into the latch nose and down the arm. It is printed lying flat with the pin vertical and bar B swung 30 degrees open, because then the hinge is plain vertical walls with a 0.4 mm gap, the latch arm bends in the layer plane, and the 45 degree ridge, groove and pin waist need no support. The pin's V-waist stops B lifting off; the socket wraps 270 degrees of the pin so it cannot pull off sideways. The arm is 3 lines (1.26 mm) wide and 12.7 mm long: the 0.9 mm snap strains it about 1 percent. Push the round bead outward to open. PETG (PLA works, with a shorter life), 0.2 mm layers, no supports.
6
+ What makes this good: every working surface is either a vertical wall or a 45 degree flank, so the mechanism is exactly what the slicer prints, and the backs of the bars are bulged where the fingers squeeze.
7
+ """
8
+ from build123d import *
9
+ from math import cos, radians, sin, sqrt
10
+
11
+ P = {
12
+ "length": 108.0, # overall, shut (published: 4 1/4 in)
13
+ "height": 9.0, # height off the bed = the clip's width across the bag
14
+ "bar_w": 7.0, # each bar, sealing face to the crown of its back
15
+ "back_bulge": 1.2, # how far the back bows out at mid-height (30 degrees at the bed, prints clean)
16
+ "seal": 0.25, # film gap between the bars, and between ridge and groove, when latched
17
+ "ridge_h": 2.2, # ridge height; its flanks are 45 degrees
18
+ "ridge_tip": 0.6, # flat on the ridge tip so it does not cut the film
19
+ "gap": 0.4, # print-in-place clearance in the hinge
20
+ "pin_r": 3.5, # hinge pin radius
21
+ "waist": 1.5, # depth of the pin's V-waist: stops bar B sliding off the pin
22
+ "socket_wall": 2.0, # wall of bar B's C-socket
23
+ "yoke_t": 2.4, # bar A's yoke round the socket
24
+ "neck_w": 2.4, # neck joining the pin to the yoke through the socket's opening
25
+ "open_max": 40.0, # degrees bar B can swing before the socket meets the neck
26
+ "print_open": 30.0, # degrees it is printed open
27
+ "arm_t": 1.26, # latch arm: 3 lines of 0.42, bends in the layer plane
28
+ "arm_slot": 0.8, # slot between the end of bar A and the arm
29
+ "foot": 1.8, # strip joining the arm to the back of bar A
30
+ "catch": 0.9, # overlap of the latch nose on bar B's back (more than the hinge play)
31
+ "latch_clear": 0.25, # clearance from bar B to the arm and to the nose, latched
32
+ "grip_r": 2.2, # round bead on the arm that the thumb pushes
33
+ }
34
+
35
+ def rect(x0, x1, y0, y1):
36
+ return Pos((x0 + x1) / 2, (y0 + y1) / 2) * Rectangle(x1 - x0, y1 - y0)
37
+
38
+ def section(side): # bar cross-section in YZ: flat sealing face at y = side * seal / 2, back bowed out for the fingers
39
+ y0, h = P["seal"] / 2, P["height"]
40
+ y1 = y0 + P["bar_w"] - P["back_bulge"]
41
+ flat = Polyline((side * y1, 0), (side * y0, 0), (side * y0, h), (side * y1, h))
42
+ back = ThreePointArc((side * y1, h), (side * (y0 + P["bar_w"]), h / 2), (side * y1, 0))
43
+ return Plane.YZ * make_face(flat.edges() + back.edges())
44
+
45
+ def waisted(r, v): # vertical pin of radius r with a 45 degree V-waist v deep at mid-height (no overhang past 45)
46
+ h = P["height"]
47
+ half = Polygon((0, 0), (r, 0), (r, h / 2 - v), (r - v, h / 2), (r, h / 2 + v), (r, h), (0, h), align=None)
48
+ return revolve(Plane.XZ * half, Axis.Z)
49
+
50
+ def build():
51
+ h, s, w, gap, clear = P["height"], P["seal"], P["bar_w"], P["gap"], P["latch_clear"]
52
+ r_sock = P["pin_r"] + gap + P["socket_wall"] # socket outside
53
+ r_yoke = r_sock + gap # yoke inside
54
+ r_head = r_yoke + P["yoke_t"] # the hinge axis is the Z axis; bars run along +X, A at -Y, B at +Y
55
+ xi = P["length"] - r_head - 2 * P["grip_r"] # inner face of the latch arm
56
+ x_a, x_b = xi - P["arm_slot"], xi - clear # ends of bar A and bar B
57
+ y_a, y_c = -(s / 2 + w), s / 2 + w + clear # back of bar A; catch face of the nose over bar B's back
58
+
59
+ # bar A: bar, yoke under and behind the socket, neck and waisted pin
60
+ yoke = Circle(r_head) - Circle(r_yoke) - Polygon((0, -s / 2), (50, -s / 2), (50, 50), (-50, 22), align=None) # keep 155 to 360 degrees
61
+ neck = rect(-r_yoke - 1, -1, -P["neck_w"] / 2, P["neck_w"] / 2)
62
+ bar_a = extrude(section(-1), x_a) - Cylinder(r_yoke, 3 * h)
63
+ # latch: foot, arm standing past bar B, nose with a lead-in ramp, round bead to push
64
+ n = P["catch"] + clear
65
+ y_top = y_c + 0.5 + 1.5 * n
66
+ arm = rect(x_a - 2, xi + P["arm_t"], y_a, y_a + P["foot"]) + rect(xi, xi + P["arm_t"], y_a, y_top)
67
+ nose = Polygon((xi + 0.1, y_c), (xi + 0.1, y_top), (xi - n, y_c + 0.5), (xi - n, y_c), align=None) # anticlockwise, so it extrudes up
68
+ bead = Pos(xi + P["grip_r"], y_top) * Circle(P["grip_r"])
69
+ a = bar_a + extrude(yoke + neck + arm + nose + bead, h) + waisted(P["pin_r"], P["waist"])
70
+
71
+ # ridge on A, and the same profile grown by the film gap as the groove in B
72
+ zc, th, tip, x0 = h / 2, P["ridge_h"], P["ridge_tip"] / 2, r_head + 1
73
+ ridge = Polygon((-s / 2 - 0.5, zc - th - tip), (-s / 2, zc - th - tip), (-s / 2 + th, zc - tip),
74
+ (-s / 2 + th, zc + tip), (-s / 2, zc + th + tip), (-s / 2 - 0.5, zc + th + tip), align=None)
75
+ a += Pos(x0, 0, 0) * extrude(Plane.YZ * ridge, x_a - 2 - x0)
76
+ groove = Pos(x0 - 1, 0, 0) * extrude(Plane.YZ * offset(ridge, s, kind=Kind.INTERSECTION), x_a - x0)
77
+
78
+ # bar B: bar and C-socket. The opening is the neck's slot (neck + gap) swept through the swing, so it is no wider than it must be.
79
+ far, slot_w = 3 * r_sock, P["neck_w"] / 2 + gap
80
+ slot, turn = rect(-far, 0, -slot_w, slot_w), radians(180 - P["open_max"])
81
+ swept = slot + Rot(0, 0, -P["open_max"]) * slot + Polygon((0, 0), (far * cos(turn), far * sin(turn)), (-far, 0), align=None)
82
+ socket = Circle(r_sock) - swept
83
+ b = extrude(section(1), x_b) + extrude(socket, h)
84
+ b -= waisted(P["pin_r"] + gap, P["waist"] - gap * (sqrt(2) - 1)) + groove # pin shape grown by gap, measured square to the surface
85
+
86
+ return Compound([a, Rot(0, 0, P["print_open"]) * b])
@@ -0,0 +1,81 @@
1
+ """Pocket clicker: a bistable double curved beam in a closed frame
2
+ Pattern: a computed 2D curve (cosine beam from a formula) made into a face, extruded flat with a filleted frame round it
3
+ Modelled on: the double curved-beam bistable mechanism of Qiu, Lang and Slocum, "A curved-beam bistable mechanism", J. Microelectromechanical Systems 13(2), 2004, pp. 137-146 (https://manuscript.isc.ac/Inventory/49/950908.htm)
4
+ Published sizes used: bistability ratio rise / thickness must exceed about 2.31 for a cosine beam clamped at both ends with its twisting mode blocked (Qiu, Lang and Slocum 2004, URL above); here rise / thickness = 3.0. All other sizes are design choices.
5
+ Concept: A one-piece fidget that snaps between two rest positions with a click. Two parallel beams, each pre-curved as one cosine wave, are clamped in the end walls of a closed frame and joined at the centre by a shuttle, so the centre cannot rotate and the beams must snap straight through instead of rolling over. Pushing the thumb pad squeezes the beams along their length; the two rails carry that thrust in tension, so the frame must be a closed ring that does not spread: if it spreads, the snap is lost. Travel stops on the rails catch the shuttle at 1.65 x rise, short of where the beams would come to rest on their own (a little under 2 x rise), so they keep pressing on the stop. MODELLED AS PRINTED, flat on the bed, because the beams must bend in the layer plane; each beam is 3 lines of 0.42 mm wide. Peak bending strain is about 2 pi^2 x thickness x rise / span^2 = 1.5 %, so print it in PETG, not brittle PLA. No supports. 1 body (print-in-place gap 0.4 mm at the stop).
6
+ What makes this good: the beam is computed from the published bistability ratio, and the frame is a rounded pebble, not a sharp slab.
7
+ """
8
+ import math
9
+ from build123d import *
10
+
11
+ P = {
12
+ "line_w": 0.42, # one extrusion line
13
+ "beam_lines": 3, # beam thickness in whole lines (3 is the least for a spring)
14
+ "rise_ratio": 3.0, # rise / thickness; must be more than 2.31 to be bistable, more gives a harder click
15
+ "span": 80.0, # beam length between the end walls; longer is softer and strains the plastic less
16
+ "beam_h": 5.0, # beam height off the bed; taller is stiffer and resists the pad tipping
17
+ "beam_pitch": 12.0, # distance between the two beams; wide apart so the shuttle cannot twist
18
+ "travel_ratio": 1.65, # stop position as a multiple of the rise; keep it under about 1.8 so the beams still press on the stop
19
+ "stop_gap": 0.4, # print-in-place gap between the shuttle and the stop it is printed against
20
+ "stop_len": 2.0, # how far each travel stop stands out from its rail
21
+ "shuttle_w": 14.0, # shuttle and thumb pad width along the beams
22
+ "shuttle_lip": 1.0, # shuttle material beyond each beam so the beams are fully buried in it
23
+ "pad_h": 11.5, # top of the thumb pad above the bed (2.5 above the frame)
24
+ "frame_h": 9.0, # frame thickness
25
+ "rail_w": 7.0, # the two long rails that carry the beam thrust in tension
26
+ "wall_w": 8.0, # the two end walls the beams are clamped in
27
+ "corner_r": 16.0, # outside corner radius in plan, so it sits in a closed hand
28
+ "edge_round": 3.5, # fillet on the frame's top outside edge
29
+ "lanyard_d": 4.0, # keyring hole through one end wall
30
+ "bed_chamfer": 1.0, # chamfer on the bed side (a fillet touching the bed prints as a ragged overhang)
31
+ }
32
+
33
+
34
+ def cosine_beam(y0, span, rise, t):
35
+ """Face of one beam: centreline y = rise/2 * (1 + cos(2 pi x / span)), thickness t measured along the normal."""
36
+ def side(sign):
37
+ pts = []
38
+ for i in range(25):
39
+ x = span * (i / 24 - 0.5)
40
+ slope = -math.pi * rise / span * math.sin(2 * math.pi * x / span)
41
+ n = math.hypot(1, slope)
42
+ y = y0 + rise / 2 * (1 + math.cos(2 * math.pi * x / span))
43
+ pts.append((x - sign * t / 2 * slope / n, y + sign * t / 2 / n))
44
+ return Spline(*pts)
45
+ upper, lower, bury = side(1), side(-1), Vector(1, 0) # each end runs 1 mm into its wall so it fuses solidly
46
+ right = Polyline(upper @ 1, (upper @ 1) + bury, (lower @ 1) + bury, lower @ 1)
47
+ left = Polyline(lower @ 0, (lower @ 0) - bury, (upper @ 0) - bury, upper @ 0)
48
+ return make_face([upper, right, lower, left])
49
+
50
+
51
+ def build():
52
+ t = P["beam_lines"] * P["line_w"]
53
+ rise = P["rise_ratio"] * t # the bistability condition, computed, not typed in
54
+ travel = P["travel_ratio"] * rise
55
+ span, pitch, lip = P["span"], P["beam_pitch"], P["shuttle_lip"]
56
+
57
+ # Two beams (ends at y = 0 and y = pitch, bowed towards +Y as printed) and the shuttle that ties their centres.
58
+ beams = cosine_beam(0, span, rise, t) + cosine_beam(pitch, span, rise, t)
59
+ sh_lo, sh_hi = rise - t / 2 - lip, pitch + rise + t / 2 + lip
60
+ shuttle = Pos(0, (sh_lo + sh_hi) / 2) * RectangleRounded(P["shuttle_w"], sh_hi - sh_lo, 5)
61
+
62
+ # Window: room for the printed position, the stop gap, and the travel to the other stop.
63
+ win_lo, win_hi = sh_lo - travel - P["stop_len"], sh_hi + P["stop_gap"] + P["stop_len"]
64
+ win_mid, win_h = (win_lo + win_hi) / 2, win_hi - win_lo
65
+ window = Pos(0, win_mid) * RectangleRounded(span, win_h, 4)
66
+ stop = Rectangle(P["shuttle_w"], P["stop_len"] + 1) # 1 mm buried in the rail
67
+ stops = Pos(0, win_hi - P["stop_len"] / 2 + 0.5) * stop + Pos(0, win_lo + P["stop_len"] / 2 - 0.5) * stop
68
+
69
+ # Closed frame: round the outside like a pebble BEFORE cutting the window, so only outside edges are touched.
70
+ outline = RectangleRounded(span + 2 * P["wall_w"], win_h + 2 * P["rail_w"], P["corner_r"])
71
+ slab = extrude(Pos(0, win_mid) * outline, P["frame_h"])
72
+ slab = fillet(slab.edges().group_by(Axis.Z)[-1], P["edge_round"])
73
+ slab = chamfer(slab.edges().group_by(Axis.Z)[0], P["bed_chamfer"])
74
+ lanyard = Pos(-(span + P["wall_w"]) / 2, win_mid) * Circle(P["lanyard_d"] / 2)
75
+ frame = slab - extrude(window + lanyard, P["frame_h"]) + extrude(stops, P["beam_h"])
76
+
77
+ # Thumb pad: the shuttle carried up above the frame, with a domed top edge for the thumb.
78
+ pad = extrude(shuttle, P["pad_h"])
79
+ pad = fillet(pad.edges().group_by(Axis.Z)[-1], 3.0)
80
+ ribs = [Pos(0, (sh_lo + sh_hi) / 2 + dy, P["pad_h"]) * Box(P["shuttle_w"], 1.2, 1.2) for dy in (-4, 0, 4)]
81
+ return frame + extrude(beams, P["beam_h"]) + (pad - ribs) # ribs across the push direction for thumb grip
@@ -0,0 +1,55 @@
1
+ """Adhesive desk cable clip (single cable, snap-in C channel on a taped pad)
2
+ Pattern: sweep a rounded (slot) section along an arc for the C ring + loft the pad up into it, fillet the lip tips
3
+ Modelled on: 3M Command Clear Round Cord Clips 17017CLR (https://argo.webstaurantstore.com/3m-command-8482-7100027385-clear-round-cord-clips-pack/39917017CLRES.html)
4
+ Published sizes used: 13/16 in (20.6 mm) = clip width, 1/2 in (12.7 mm) = clip depth (retailer, URL above); cable diameter, mouth and wall are design choices
5
+ Concept: A stick-on clip that parks one charging cable at the desk edge. The cable is pushed down through a mouth narrower than itself; the two lips of the C ring spring apart and close over it, so it slides lengthways but cannot lift out. The pull of the cable goes round the ring, down the lofted neck and spreads over the whole pad, which is flat for a foam tape square. Prints as modelled, pad on the bed, no supports (the channel is a 5.6 mm bridge-free arch). The lips are 4 lines wide and the ring is one continuous sweep, so the perimeters run round the C; the flex still crosses layers at the ring's sides, so print PETG (or PLA for light cables) and do not shrink the mouth below about 70% of the cable.
6
+ What makes this good: one swept ring with fully rounded lips and a neck that flows into the pad, so it reads as a moulded clip rather than a bracket.
7
+ """
8
+ from math import asin, degrees
9
+
10
+ from build123d import *
11
+
12
+ P = {
13
+ "cable_d": 5.0, # cable it holds (design choice: a thick USB-C or power lead)
14
+ "channel_clear": 0.6, # channel is this much bigger than the cable so it slides
15
+ "mouth": 3.6, # gap between the lips; the cable squeezes through (72% of cable_d)
16
+ "lip_t": 1.68, # ring wall = 4 x 0.42 mm lines, thin enough to spring
17
+ "ring_w": 8.0, # ring length along the cable; wide so the jacket is not creased
18
+ "tip_r": 0.7, # rounding of the lip tips (finger and cable lead-in)
19
+ "pad_l": 20.6, # pad length across the cable (published clip width)
20
+ "pad_w": 12.7, # pad width along the cable (published clip depth)
21
+ "pad_t": 1.2, # pad edge thickness
22
+ "pad_corner_r": 4.0, # plan corner radius of the pad
23
+ "seat_h": 3.4, # underside of the cable above the taped face
24
+ "cradle": 0.5, # neck rises to this fraction of the channel radius below its centre
25
+ }
26
+
27
+
28
+ def build():
29
+ r_in = (P["cable_d"] + P["channel_clear"]) / 2
30
+ r_mid, r_out = r_in + P["lip_t"] / 2, r_in + P["lip_t"]
31
+ zc = P["seat_h"] + r_in # channel centre height
32
+
33
+ # C ring: one sweep round the cable axis (Y), open at the top by the mouth angle
34
+ half_mouth = degrees(asin(P["mouth"] / 2 / r_in))
35
+ arc = Plane.XZ * CenterArc((0, zc), r_mid, 90 + half_mouth, 360 - 2 * half_mouth)
36
+ section = Plane(arc @ 0, x_dir=(0, 1, 0), z_dir=arc % 0) * SlotOverall(P["ring_w"], P["lip_t"])
37
+ ring = sweep(section, path=arc)
38
+ # round the two lip tips: the only flat faces on the ring are its ends
39
+ tips = ring.faces().filter_by(GeomType.PLANE).edges()
40
+ ring = fillet(tips, P["tip_r"])
41
+
42
+ # pad + neck: loft from the tape footprint up round the lower third of the ring, so the
43
+ # cable's pull spreads into the whole pad and only the upper lips are free to spring
44
+ neck_top = zc - r_in * P["cradle"]
45
+ neck_l = 2 * (r_out**2 - (zc - neck_top) ** 2) ** 0.5 # chord of the ring at that height
46
+ base = loft([
47
+ Plane.XY * RectangleRounded(P["pad_l"], P["pad_w"], P["pad_corner_r"]),
48
+ Plane.XY.offset(P["pad_t"]) * RectangleRounded(P["pad_l"] - 1, P["pad_w"] - 1, P["pad_corner_r"] - 0.5),
49
+ Plane.XY.offset(P["pad_t"] + 0.8) * RectangleRounded(neck_l + 3, P["ring_w"], 2.5),
50
+ Plane.XY.offset(neck_top) * RectangleRounded(neck_l, P["ring_w"] - 1.5, 2.0),
51
+ ])
52
+ # clear the channel out of the neck; cutting at mid-wall hides the cut inside the ring,
53
+ # so the cable only ever touches the smooth swept surface
54
+ base -= Pos(0, 0, zc) * Rot(90, 0, 0) * Cylinder(r_mid, P["pad_w"])
55
+ return base + ring
@@ -0,0 +1,45 @@
1
+ """Chainmail patch: rigid square links that pass through each other, printed in place
2
+ Pattern: one link made from a rounded ring with two box cuts (two bars stay on the bed, two become bridges), then copied on a grid as a Compound of separate solids
3
+ Modelled on: NASA/JPL "space fabric" (https://www.jpl.nasa.gov/news/space-fabric-links-fashion-and-engineering) and Ed Nisley's printable chain mail (https://softsolder.com/2014/12/04/3d-printed-chain-mail-armor-cosplay-edition/)
4
+ Published sizes used: 2.4 mm = bar width, 6 threads of 0.40 mm (maker, https://softsolder.com/2014/12/04/3d-printed-chain-mail-armor-cosplay-edition/); JPL publishes no sizes; the other sizes are design choices
5
+ Concept: A flexible sheet of hard links for costume mail, a trivet, a strap or a fidget, printed flat in one go: rows x cols separate bodies (16 by default). Each link is a square ring whose two bars along X lie on the bed and whose two bars along Y are lifted one clearance higher, carried as short bridges by the four full-height corner posts. Turned 45 degrees and set on a square grid, every link's corner post stands inside the opening of each neighbour, so each pair of rings is threaded like two links of a chain; pull on the sheet and the load goes ring to ring through the posts. Flat feet (the low bars and posts) hold every link to the bed, the bridges span 7.2 mm over the two neighbour bars that pass under them, and nothing overhangs, so no supports. The raised bars are rounded for the hand; the bed edges are chamfered so first-layer squash cannot join neighbours. PETG or PLA, 0.2 mm layers.
6
+ What makes this good: the clearances are stated numbers that the pitch is derived from, so changing the link size keeps the links free, and solid_count proves they did not fuse.
7
+ """
8
+ from build123d import *
9
+ from math import sqrt
10
+
11
+ P = {
12
+ "rows": 4, # links along Y
13
+ "cols": 4, # links along X
14
+ "link": 12.0, # outside of one square link (must be at least 4 * bar + 3 * gap)
15
+ "bar": 2.4, # bar width, and the outside corner radius: 6 lines of 0.4
16
+ "bar_t": 1.2, # bar thickness: 6 layers
17
+ "lift": 0.8, # vertical clearance between a low bar and the bridge over it: 4 layers
18
+ "gap": 0.7, # horizontal clearance between a neighbour's post and this link's bars
19
+ "top_r": 0.8, # rounding of the raised bars, the side the hand feels
20
+ "foot_chamfer": 0.3, # chamfer on the bed edges
21
+ }
22
+
23
+ # Why the links cannot come apart. Take a link at the origin, unrotated, and its neighbour one pitch away on the diagonal
24
+ # (pitch = link - 2 * bar - gap = 6.5). This link's corner post spans 3.6 to 6.0 in X and Y; the neighbour's near bars and
25
+ # post span 0.5 to 2.9, so the neighbour's post stands INSIDE this ring's opening (-3.6 to 3.6) and this post stands inside
26
+ # the neighbour's. Each ring is closed, so the two are threaded like chain links: this link's low bar (z 0 to 1.2) runs
27
+ # under the neighbour's bridge (z from 2.0) and its own bridge runs over the neighbour's low bar. To separate, a bar would
28
+ # have to pass through a bar. Gaps, from those coordinates: post to bar 3.6 - 2.9 = 0.7; post to the next neighbour's post
29
+ # 0.5 - (-0.5) = 1.0; link to the link two pitches away 13.0 - 12.0 = 1.0; low bar to bridge 2.0 - 1.2 = 0.8. All above 0.4.
30
+
31
+ def link():
32
+ s, b, t = P["link"], P["bar"], P["bar_t"]
33
+ high = t + P["lift"] # underside of the bridges
34
+ ring = extrude(RectangleRounded(s, s, b) - Rectangle(s - 2 * b, s - 2 * b), high + t)
35
+ low_align = (Align.CENTER, Align.CENTER, Align.MIN)
36
+ ring -= Pos(0, 0, t) * Box(s - 2 * b, 2 * s, high, align=low_align) # bars along X keep only their bottom: feet on the bed
37
+ ring -= Box(2 * s, s - 2 * b, high, align=low_align) # bars along Y keep only their top: bridges between the posts
38
+ ring = fillet(ring.edges().group_by(Axis.Z)[-1], P["top_r"]) # soft raised bars
39
+ return chamfer(ring.edges().group_by(Axis.Z)[0], P["foot_chamfer"]) # room for first-layer squash
40
+
41
+ def build():
42
+ pitch = P["link"] - 2 * P["bar"] - P["gap"] # diagonal neighbour spacing that leaves `gap` beside each post
43
+ step = pitch * sqrt(2) # the same lattice turned 45 degrees is a plain square grid
44
+ one = Rot(0, 0, 45) * link()
45
+ return Compound([Pos(c * step, r * step, 0) * one for r in range(P["rows"]) for c in range(P["cols"])])
@@ -0,0 +1,101 @@
1
+ """Hinged pill and parts box with a snap latch, printed in place
2
+ Pattern: model the lid CLOSED on the box, then swing it 180 degrees about the pin axis into the flat printed pose; hull-profile knuckles with cone pin ends cut as cone sockets
3
+ Modelled on: rose plastic UniBox, a polypropylene hinged box with a press closure (https://shop.rose-plastic.de/en_10/plastic-boxes/unibox.html; the page lists no box this small, the smallest read was 100 x 100 mm inside)
4
+ Published sizes used: none published; sizes are design choices
5
+ Concept: A pocket box for pills or small screws, in 2 bodies: the box (two outer hinge knuckles, the latch spring) and the lid (centre knuckle, locating lip, thumb finger). It is printed open and flat, box and lid side by side with the knuckles between them, because that is the only pose in which both halves stand on the bed with their open sides up, so nothing inside needs support and the hinge prints with a clean gap; it comes off the bed as one working piece. That layout fixes the pin at half the closed height. The lid knuckle ends in a 45 degree cone each side, seated in a cone socket in the box knuckles with 0.4 mm all round, so the pin is captive as printed and its overhangs never pass 45 degrees. Closed, the lid's lip drops inside the box mouth and takes side knocks; the hinge side has no lip because the hinge already locates that edge. The latch is a leaf spring 3 lines (1.26 mm) wide standing along the front wall, bending in the layer plane, with the wall 0.9 mm behind it as its hard stop: the barb on the lid's finger cams the leaf in 0.5 mm and snaps under its nose, and the 45 degree catch faces let a firm pull, or a press on the leaf, open it. PETG or PLA, 0.2 mm layers, no supports.
6
+ What makes this good: it is drawn closed, where the fits are easy to reason about, and one rotation about the pin gives the printable pose, so the closed fit and the printed gaps cannot disagree.
7
+ """
8
+ from build123d import *
9
+ from math import sqrt
10
+
11
+ P = {
12
+ "length": 60.0, # along the hinge (Y), outside
13
+ "width": 40.0, # hinge side to latch side (X), outside
14
+ "box_h": 14.0, # box height including the floor
15
+ "lid_h": 6.0, # lid height including its top
16
+ "wall": 1.6, # walls, floor and lid top: 4 lines of 0.4
17
+ "corner_r": 6.0, # plan corner radius, comfortable in a pocket
18
+ "edge_r": 1.5, # rounded floor edge and lid top edge (small enough to print on the bed)
19
+ "scoop_r": 3.0, # fillet inside the floor so a fingertip can sweep a pill out
20
+ "lip_h": 1.6, # how far the lid's lip drops into the box
21
+ "lip_t": 1.2, # lip thickness: 3 lines
22
+ "lip_fit": 0.25, # lip to box wall, each side
23
+ "gap": 0.4, # print-in-place clearance, hinge faces and cones
24
+ "hinge_off": 4.5, # pin axis to the back walls
25
+ "knuckle_r": 3.0, # knuckle outer radius
26
+ "pin_r": 2.0, # cone pin radius at its root
27
+ "pin_tip_r": 0.6, # cone pin radius at its flat tip
28
+ "box_knuckle": 8.0, # length of each of the box's two knuckles
29
+ "lid_knuckle": 16.0, # length of the lid's centre knuckle
30
+ "leaf_t": 1.26, # latch leaf spring: 3 lines of 0.42, bends in the layer plane
31
+ "leaf_len": 16.0, # free length of the leaf (0.9 mm at the tip strains it under 1 percent)
32
+ "stop_gap": 0.9, # leaf to front wall: the wall is the hard stop
33
+ "nose": 0.8, # how far the leaf's nose stands out
34
+ "catch": 0.5, # overlap of nose and barb = the stroke to open
35
+ "latch_play": 0.2, # vertical play between the catch faces when shut
36
+ "latch_w": 8.0, # width of the nose; the finger is 2 mm wider
37
+ "finger_t": 2.4, # thickness of the lid's thumb finger
38
+ }
39
+
40
+ def rect(x0, x1, y0, y1):
41
+ return Pos((x0 + x1) / 2, (y0 + y1) / 2) * Rectangle(x1 - x0, y1 - y0)
42
+
43
+ def plan(inset=0.0): # the rounded footprint, shared by box, cavity, lid and lip
44
+ return RectangleRounded(P["width"] - 2 * inset, P["length"] - 2 * inset, P["corner_r"] - inset)
45
+
46
+ def knuckle(za, z0, z1, y_len): # round eye on the pin axis, hulled to the face of its own wall between z0 and z1
47
+ d = P["hinge_off"]
48
+ eye = Pos(0, za) * Circle(P["knuckle_r"])
49
+ web = make_hull(eye.edges() + rect(-d, -d + 0.1, z0, z1).edges()) + rect(-d - P["wall"] / 2, -d, z0, z1) # second term keys it into the wall
50
+ return extrude(Plane.XZ * web, y_len / 2, both=True)
51
+
52
+ def pin_end(za, grow): # 45 degree cone along +Y from the lid knuckle's end face; grow > 0 makes the socket `grow` larger all round
53
+ r, tip = P["pin_r"], P["pin_tip_r"]
54
+ cone = Cone(r + grow * sqrt(2), tip + grow * (sqrt(2) - 1), r - tip + grow, align=(Align.CENTER, Align.CENTER, Align.MIN))
55
+ return Pos(0, P["lid_knuckle"] / 2, za) * Rot(-90, 0, 0) * cone
56
+
57
+ def build():
58
+ W, hb, hl, t, gap, d = P["width"], P["box_h"], P["lid_h"], P["wall"], P["gap"], P["hinge_off"]
59
+ za = (hb + hl) / 2 # pin height: half the closed height, so the opened lid lands on the bed
60
+ lo = za - d - P["knuckle_r"] * sqrt(2) # lowest wall point a knuckle web may reach and still rise at 45 degrees
61
+ at_box = Pos(-(d + W / 2), 0, 0) # the pin axis is the Y axis at height za; the box sits on its -X side
62
+ swing_open = Pos(0, 0, za) * Rot(0, 180, 0) * Pos(0, 0, -za)
63
+
64
+ # box: rounded shell with a scooped floor, two outer knuckles with cone sockets
65
+ shell = extrude(plan(), hb)
66
+ shell = fillet(shell.edges().group_by(Axis.Z)[0], P["edge_r"])
67
+ cavity = extrude(Pos(0, 0, t) * plan(t), hb)
68
+ shell -= fillet(cavity.edges().group_by(Axis.Z)[0], P["scoop_r"])
69
+ box_k = Pos(0, (P["lid_knuckle"] + P["box_knuckle"]) / 2 + gap, 0) * knuckle(za, lo, hb, P["box_knuckle"]) - pin_end(za, gap)
70
+ box = at_box * shell + box_k + mirror(box_k, Plane.XZ)
71
+
72
+ # lid, drawn closed on top of the box: cap, lip hanging into the mouth (not on the hinge side), centre knuckle with cone ends
73
+ cap = extrude(Pos(0, 0, hb) * plan(), hl)
74
+ cap = fillet(cap.edges().group_by(Axis.Z)[-1], P["edge_r"])
75
+ a = t + P["lip_fit"]
76
+ lip = extrude(Pos(0, 0, hb - P["lip_h"]) * plan(a), P["lip_h"])
77
+ lip -= Pos(W / 2, 0, hb - P["lip_h"] / 2) * Box(2 * P["corner_r"], P["length"], P["lip_h"]) # a lip here would swing through the back wall
78
+ hollow = extrude(Pos(0, 0, hb - P["lip_h"]) * plan(a + P["lip_t"]), P["lip_h"] + hl - t)
79
+ lid_k = knuckle(za, hb, 2 * za - lo, P["lid_knuckle"]) + pin_end(za, 0) + mirror(pin_end(za, 0), Plane.XZ)
80
+ lid = at_box * (cap + lip - hollow) + lid_k
81
+
82
+ # latch, in the closed pose. out(x, z) is a point x outside the front wall at height z.
83
+ xf = -(d + W)
84
+ out = lambda x, z: (xf - x, z)
85
+ face, zt, half = P["stop_gap"] + P["leaf_t"], hb - gap, P["latch_w"] / 2 # leaf outer face; leaf top, clear of the finger above it
86
+ tip = face + P["nose"] # nose tip
87
+ zn = zt - 1.5 * P["nose"] - gap # bottom of the nose's flat tip
88
+ leaf = rect(xf - face, xf - P["stop_gap"], half - P["leaf_len"], half) # stands on the bed, free at +Y
89
+ root = rect(xf - face, xf + t / 2, half - P["leaf_len"] - 2 * P["leaf_t"], half - P["leaf_len"])
90
+ nose = Polygon(out(face - 0.2, zt), out(face, zt), out(tip, zt - 1.5 * P["nose"]), out(tip, zn), out(face - 0.2, zn - P["nose"] - 0.2), align=None)
91
+ box += extrude(leaf + root, zt) + extrude(Plane.XZ * nose, half, both=True) # nose underside is 45 degrees: catch face, and printable
92
+
93
+ fi, b = tip + gap, P["catch"] + gap # finger inner face clears the nose tip; barb reaches `catch` under the nose
94
+ zc = zn + P["latch_play"] # top of the barb's 45 degree catch face, parallel to the nose's
95
+ zb = zc - b - gap # bottom of the barb's flat tip; the lead-in ramp runs down from here
96
+ finger = Polygon(out(-t / 2, hb), out(fi, hb), out(fi, zc), out(fi - b, zc - b), out(fi - b, zb), out(fi, zb - 1.5 * b),
97
+ out(fi + P["finger_t"], zb - 1.5 * b), out(fi + P["finger_t"], hb + hl), out(-t / 2, hb + hl), align=None)
98
+ finger = extrude(Plane.XZ * finger, half + 1, both=True)
99
+ lid += fillet(finger.edges().filter_by(Axis.Z).group_by(Axis.X)[0], 1.0) # soft corners where the thumb lifts
100
+
101
+ return Compound([box, swing_open * lid])
@@ -0,0 +1,50 @@
1
+ """Fluted clamping knob that captures an M6 hex bolt head
2
+ Pattern: revolve a rounded 2D profile, then pattern a cutter round the axis (polar flutes) and cut the hex pocket
3
+ Modelled on: JW Winco GN 7336 hollow knurled knob, size 34 (https://www.jwwinco.com/en-us/products/2.2-Tensioning-clamping-with-handles/Knurled-knobs/GN-7336-Plastic-Hollow-Knurled-Knobs-without-Tapped-Insert)
4
+ Published sizes used: grip diameter d1 = 34, hub d3 = 16, height h1 = 21, bore d4 = 6.1, hexagon A/F = 10 (maker, URL above, converted from its inch table); M6 hex head across flats s = 10, head height k = 4 (ISO 4017, https://boltsparts.github.io/en/parts/standards/ISO4017.html)
5
+ Concept: A thumb knob that turns an ordinary M6 hex bolt into a clamping screw. The bolt drops in from the top, its head sits in the hex pocket and the thread leaves through the hub. Turning the knob drives the six flats; tightening pulls the head down onto the pocket floor, which is the full solid hub, so the clamp load goes straight through the hub into the work. Prints as modelled: hub on the bed, hex pocket UP, no supports, because the underside of the grip is a 45 degree cone and the pocket is open to the top. PETG or PLA, 4 walls. One body.
6
+ What makes this good: the crowned top and rounded rim sit in the palm, and eighteen finger-width flutes give grip without sharp teeth.
7
+ """
8
+ from build123d import *
9
+
10
+ P = {
11
+ "grip_d": 34.0, # d1, the diameter the fingers hold (maker)
12
+ "hub_d": 16.0, # d3, the narrow hub that bears on the work (maker)
13
+ "height": 21.0, # h1, overall (maker)
14
+ "bore_d": 6.1, # d4, through hole for the M6 thread (maker)
15
+ "hex_af": 10.0, # s, M6 head across flats (ISO 4017)
16
+ "head_k": 4.0, # k, M6 head height (ISO 4017)
17
+ "fit": 0.3, # print allowance added to the hex A/F and the bore diameter
18
+ "head_recess": 1.0, # how far the head sits below the crown, so the palm never feels it
19
+ "hub_h": 3.0, # straight hub before the 45 degree cone starts
20
+ "crown": 2.5, # rise of the domed top above the rim
21
+ "rim_round": 2.5, # radius on the rim's top and bottom corners
22
+ "flutes": 18, # grooves round the rim, about one per 6 mm of rim
23
+ "flute_r": 2.4, # radius of each groove cutter (a fingertip-sized scallop)
24
+ "flute_depth": 1.1, # how deep each groove bites into the rim
25
+ }
26
+
27
+
28
+ def build():
29
+ R, r_hub, H = P["grip_d"] / 2, P["hub_d"] / 2, P["height"]
30
+ z_cone = P["hub_h"] + (R - r_hub) # 45 degree underside: it rises as far as it widens, so it prints unsupported
31
+ z_rim = H - P["crown"]
32
+
33
+ # Half profile in (radius, height): crown arc that is flat at the axis, rim, 45 degree cone, hub with a bed chamfer.
34
+ crown = TangentArc((0, H), (R, z_rim), tangent=(1, 0))
35
+ side = Polyline((R, z_rim), (R, z_cone), (r_hub, P["hub_h"]), (r_hub, 0.6), (r_hub - 0.6, 0), (0, 0), (0, H))
36
+ profile = make_face([crown, side])
37
+ rim_corners = profile.vertices().sort_by(Axis.X)[-2:] # the two corners at the grip radius
38
+ profile = fillet(rim_corners, P["rim_round"]) # round them in 2D, before revolving
39
+ body = revolve(Plane.XZ * profile, Axis.Z)
40
+
41
+ # Pattern one groove cutter round the axis. Its centre is outside the rim so only a shallow scallop is cut.
42
+ pitch_r = R + P["flute_r"] - P["flute_depth"]
43
+ groove = Cylinder(P["flute_r"], 3 * H) # full height: it fades out down the cone and never reaches the hub
44
+ body -= [loc * groove for loc in PolarLocations(pitch_r, P["flutes"])]
45
+
46
+ # Hex pocket for the bolt head (open to the top) and the through hole for its thread.
47
+ floor_z = H - P["head_recess"] - P["head_k"]
48
+ pocket = extrude(RegularPolygon((P["hex_af"] + P["fit"]) / 2, 6, major_radius=False), H)
49
+ bore = Cylinder((P["bore_d"] + P["fit"]) / 2, 3 * H)
50
+ return body - Pos(0, 0, floor_z) * pocket - bore