@rulecad/cad 0.7.48 → 0.7.53

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.
package/AGENTS.md CHANGED
@@ -30,7 +30,7 @@ variable says which rule it comes from. Follow these steps; they're what makes a
30
30
  1. `npx cad history <project>/<object>` first: read the print log. A failed print is the reason for most changes:
31
31
  fix the rule or variable it points at (a measured fit beats a community rule).
32
32
  2. Change, then check, preview and look, as for a new part. Change values with `npx cad set <project>/<object>
33
- name=value` and assemblies with `npx cad add fit|joint|item|pose …`: they keep the file's layout and refuse an edit
33
+ name=value` and assemblies with `npx cad add fit|joint|item|pose|fasten …`: they keep the file's layout and refuse an edit
34
34
  that breaks it. `npx cad values` lists an object's numbers; `npx cad why <project>/<object>.<name>` shows what a
35
35
  value depends on, down to the rules (estimates marked). `--json` on check, values and why gives data to act on:
36
36
  each finding has a code, its numbers and where it is.
@@ -43,15 +43,23 @@ variable says which rule it comes from. Follow these steps; they're what makes a
43
43
  - Walls are whole numbers of print lines (`x1c.line * 3`, or your printer's set), heights whole numbers of layers.
44
44
  - Holes and slots get the printer's hole compensation; parts that slide together get its fit clearance. Chamfer
45
45
  bottom edges.
46
+ - A hole or a seat for a screw, a nut or a heat-set insert comes from `v.fixings`, named by its thread, never from a
47
+ typed number: `v.fixings.hole('M3', { kind: 'pilot', at })` (kinds: `clearance`, `close`, `loose`, `pilot`, `tap`,
48
+ `insert`, `thread`), `counterbore`, `countersink`, `nutPocket`, `nutTrap`, `squareNutSlot`, `insertBoss`. Each reads
49
+ the workspace's thread set (`rules/m3.json` before the kit's), the project's printer and its material, so no
50
+ diameter is typed and none is passed in. `cad check` then says what each was drawn to and the rule it rests on:
51
+ report a figure it marks as an estimate or a community figure, and measure it. A thread's name is text
52
+ (`'M3x12 cap'`), so the check on numbers passes it.
46
53
  - An overhang warning means supports: say so in `orientation`, or change the shape or orientation.
47
54
  - A part that moves by bending (a spring, a snap, a hinge with no pin) is a flexure from `v.flexures`: drawn flat, so it
48
55
  bends within its layers; give its thickness in whole lines (`x1c.line`), and check its strain at the travel against
49
56
  the material's limit with `v.flexures.printable`. PLA creeps held bent and fatigues; PETG or nylon for springs.
50
- - Use the print-aware features in `v.shapes` before drawing your own: `countersink`, `teardropHole`, `nutPocket`,
51
- `crushRibs`, `wallOpening` print without supports as drawn. Use `v.ops.union/subtract/intersect` for booleans: the
57
+ - Use the print-aware features in `v.shapes` before drawing your own: `teardropHole`, `crushRibs`, `wallOpening`
58
+ print without supports as drawn (and `countersink` and `nutPocket` for a size that is no screw's). Use `v.ops.union/subtract/intersect` for booleans: the
52
59
  workspace can switch them to Manifold (faster, watertight) without touching the design.
53
- - Designs run sandboxed: they may import only `@jscad/modeling`, `@rulecad/shapes`, `@rulecad/flexures` and files in
54
- their project, and can't write files or start programs. To see a value while designing, `console.log` it: it comes
60
+ - Designs run sandboxed: they may import only `@jscad/modeling`, `@rulecad/shapes`, `@rulecad/flexures`,
61
+ `@rulecad/gears`, `@rulecad/motors`, `@rulecad/fixings` and files in their project, and can't write files or start
62
+ programs. To see a value while designing, `console.log` it: it comes
55
63
  out with the command's output. A misspelt `v.name` stops the build and says which name was meant.
56
64
  - Something printed under the part and removed afterwards is a named `support` part (`return { cap, pillar }`, both
57
65
  described in the .json's `parts`), not part of the shape. Look at `cad preview --explode` too.
@@ -73,7 +81,13 @@ variable says which rule it comes from. Follow these steps; they're what makes a
73
81
  them with joints, name the positions in `poses`, and run `cad check --sweep` to find where parts collide on the way.
74
82
  See "Joints and poses" in the cad README.
75
83
  - A part is named in fits as `<item>.<part>`; an object that returns one unnamed shape has one part, `body`.
76
- - A gap fit can't tell whether holes line up. Where a board screws into a part, add a holes fit
84
+ - Where parts screw together, say so with `fasten`, which knows the screw:
85
+ `{ "screw": "M3 cap", "through": ["bracket"], "into": "base", "at": ["bracket.h1", "bracket.h2"] }` (anchors on the
86
+ holes' axes), or `"holes": "bracket.body"` to use the part's own holes; `npx cad add fasten …` writes it. The check
87
+ reads the holes from the parts as drawn: one axis through the stack, a clearance hole in each part passed, a pilot,
88
+ insert or nut at the far end, the length chosen from what is sold, thread engaged, and the seat under the head.
89
+ Report what it finds with its numbers, and fix the part, never the relation, to make it pass.
90
+ - A gap fit can't tell whether holes line up. Where a board only rests on its screws' bosses, a holes fit follows them
77
91
  (`{ "holes": "pcb.board", "into": "case.body", "depth": "m2.insert_length" }`).
78
92
  - A part built around another (a case around its board) reads it: `"uses": ["macropad/pcb"]`, then
79
93
  `pcb.board_w` and `v.pcb.board_holes`. Never copy another object's numbers by hand.
package/EXAMPLES.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [The tutorial](TUTORIAL.md) ends with a wall hook checked against its screw. These examples carry on from there, one
4
4
  for each thing the [README](README.md) describes after that: parts, variants and releases, joints and poses, a model
5
- from elsewhere, an optimised part, a board, a mechanism printed flat, gears, a gearbox, a motor, a robot joint, and a machine sized from its task. Each is a few files and the commands to run
5
+ from elsewhere, an optimised part, a board, a mechanism printed flat, gears, a gearbox, a motor, a robot joint, a machine sized from its task, and a bracket screwed on. Each is a few files and the commands to run
6
6
  them. The tests write every file here and run every command, so what you read is what works.
7
7
 
8
8
  They start from a workspace `npm create rulecad my-designs` makes, as the tutorial does, and run in order: later
@@ -5748,3 +5748,349 @@ Said plainly, because a gait that passes these checks is not a robot that walks:
5748
5748
 
5749
5749
  `npm create rulecad --machine leg` starts a project from the leg and its stand. The step file for a gait, for a streamer grown to more axes, is not done yet, and neither is a measured leg.
5750
5750
 
5751
+
5752
+ ## 15. Fixings: a bracket screwed on
5753
+
5754
+ A small shelf bracket and the wall plate it screws to. Every hole and seat in them comes from `v.fixings`, named by its
5755
+ thread and never by a typed diameter: a counterbore and its clearance hole for the screws' heads, a pilot the screw
5756
+ cuts its own thread in, a boss for a heat-set insert, a slot a nut drops into, and countersinks. The assembly says which
5757
+ screws join what with `fasten`, and the check follows each screw along its axis: whether the holes line up, what holds
5758
+ its far end, how long it should be, how much thread it has, what its head sits on, whether a hex key reaches it, and
5759
+ what the shelf's weight does to it. Two mistakes follow, each caught by name. [Choosing a pilot, an insert or a
5760
+ nut](../../docs/guides/pilot-insert-nut.md) explains when each end is the right one.
5761
+
5762
+ The bracket is shown with all three ends at once, so one small model shows each. A real one would use one kind.
5763
+
5764
+ ```json projects/fix/project.json
5765
+ {
5766
+ "name": "fix",
5767
+ "title": "A bracket screwed on",
5768
+ "printer": "x1c",
5769
+ "material": "PLA",
5770
+ "objects": ["plate", "bracket", "wall"]
5771
+ }
5772
+ ```
5773
+
5774
+ ### The plate
5775
+
5776
+ It goes flat on the bed with its back down, and the back goes on the wall. Four posts stand out of it for the
5777
+ bracket's foot to rest on. One is the insert's boss from `insertBoss`; the other three are the same column, flared at
5778
+ the root the same way, so no inside corner is square. The top post has a pilot; the two in the middle are passed
5779
+ right through by screws coming from behind, their heads sunk flush with the back in countersinks that open on to the
5780
+ bed (a 45° cone, which prints). Two M4 countersinks at the ends take the wall's own screws, chosen for the wall.
5781
+
5782
+ ```json projects/fix/objects/plate.json
5783
+ {
5784
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
5785
+ "name": "plate",
5786
+ "title": "Wall plate",
5787
+ "version": "0.1.0",
5788
+ "uses": ["x1c"],
5789
+ "material": "PLA",
5790
+ "orientation": "Flat, its back on the bed: the back goes against the wall, the four posts stand out from it",
5791
+ "variables": {
5792
+ "thick": { "value": "x1c.layer * 15", "unit": "mm", "rule": "The plate: whole layers, and enough for the wall screws' M4 countersinks, 2.2 mm deep" },
5793
+ "stand": { "value": "x1c.layer * 34", "unit": "mm", "rule": "The posts: as tall as the insert's hole is deep, in whole layers, so the insert's boss is a post" },
5794
+ "pitch": { "value": 32, "unit": "mm", "rule": "Between the two screws from the front, up the wall: as the bracket's" },
5795
+ "nut_pitch": { "value": 12, "unit": "mm", "rule": "Between the two screws from behind, up the wall: as the bracket's nuts" },
5796
+ "width": { "value": 20, "unit": "mm", "rule": "Across the plate: a post and a few mm each side" },
5797
+ "long": { "value": 70, "unit": "mm", "rule": "Up the plate: the bracket's foot and a wall screw beyond each end" },
5798
+ "round": { "value": 4, "unit": "mm", "rule": "The plate's corners, rounded" },
5799
+ "wall_pitch": { "value": 58, "unit": "mm", "rule": "Between the wall screws, clear of the bracket's foot and the posts" },
5800
+ "floor": { "value": "x1c.layer * 5", "unit": "mm", "rule": "Plastic left under the pilot, so it does not break through the back" }
5801
+ }
5802
+ }
5803
+ ```
5804
+
5805
+ ```js projects/fix/objects/plate.js
5806
+ // The wall plate: four posts for the bracket, each the end its screw needs, and two countersunk holes for the wall.
5807
+ import jscad from '@jscad/modeling'
5808
+ const { roundedRectangle, cylinder, cylinderElliptic } = jscad.primitives
5809
+ const { extrudeLinear } = jscad.extrusions
5810
+
5811
+ export function main (v) {
5812
+ const f = v.fixings, top = v.thick + v.stand
5813
+ const slab = extrudeLinear({ height: v.thick }, roundedRectangle({ size: [v.width, v.long], roundRadius: v.round }))
5814
+ // the insert's boss, from the kit; the other posts are the same column, flared at the root the same way
5815
+ const boss = f.insertBoss('M3', { height: v.stand, at: [0, 0 - v.pitch / 2, v.thick] }), R = boss.model.outer / 2, root = boss.model.root
5816
+ const post = (y) => v.ops.union(cylinderElliptic({ height: root, startRadius: [R + root, R + root], endRadius: [R, R], center: [0, y, v.thick + root / 2] }),
5817
+ cylinder({ radius: R, height: v.stand, center: [0, y, v.thick + v.stand / 2] }))
5818
+ const body = v.ops.union(slab, boss.boss, post(v.pitch / 2), ...[-1, 1].map((s) => post(s * v.nut_pitch / 2)))
5819
+ return v.ops.subtract(body, boss.hole,
5820
+ f.hole('M3', { kind: 'pilot', depth: top - v.floor, at: [0, v.pitch / 2, top] }),
5821
+ ...[-1, 1].map((s) => f.countersink('M3', { length: top, thickness: top, into: '+z', at: [0, s * v.nut_pitch / 2, 0] })),
5822
+ ...[-1, 1].map((s) => f.countersink('M4', { length: v.thick, thickness: v.thick, at: [0, s * v.wall_pitch / 2, v.thick] })))
5823
+ }
5824
+ ```
5825
+
5826
+ ### The bracket
5827
+
5828
+ The bracket prints on its side: the web, the triangle that carries the shelf, lies flat on the bed, and the foot stands
5829
+ up from its back edge. So the first layer is one plain shape, the inside corner between web and foot is a 45° fillet,
5830
+ and every hole through the foot lies on its side: a counterbore and its hole are one teardrop cutter, with 45° roofs.
5831
+ The nut's slot opens at the top of the foot as it prints, and the nut drops in from there, so nothing spans. The web's
5832
+ lower end is deep enough (`heel`) that the foot and its fillet stand on it all the way along.
5833
+
5834
+ ```json projects/fix/objects/bracket.json
5835
+ {
5836
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
5837
+ "name": "bracket",
5838
+ "title": "Shelf bracket",
5839
+ "version": "0.1.0",
5840
+ "uses": ["x1c"],
5841
+ "material": "PLA",
5842
+ "orientation": "On its side: the web flat on the bed, the foot standing up from its back edge, the nuts' slots open at the top",
5843
+ "variables": {
5844
+ "web": { "value": "x1c.layer * 15", "unit": "mm", "rule": "The web's thickness, flat on the bed: 3 mm carries the shelf 80 times over (EXAMPLES chapter 15 works it); thinner is a floppy edge" },
5845
+ "wide": { "value": 44, "unit": "mm", "rule": "Up the wall: the four screws and the foot's ends" },
5846
+ "reach": { "value": 40, "unit": "mm", "rule": "Out from the wall: the shelf's depth it carries" },
5847
+ "heel": { "value": 14, "unit": "mm", "rule": "The web's depth at its lower end: under the whole foot and its fillet, so neither hangs in the air" },
5848
+ "foot": { "value": "x1c.layer * 32", "unit": "mm", "rule": "The foot's thickness, where the screws pass: a counterbored head, and the nut's slot with plastic each side of it" },
5849
+ "out": { "value": 25, "unit": "mm", "rule": "The foot, out to one side of the web: room for the screws and the nuts' slots beyond them" },
5850
+ "at": { "value": 14, "unit": "mm", "rule": "The screws' line, from the web's face: clear of the web and its fillet for the head and the key" },
5851
+ "pitch": { "value": 32, "unit": "mm", "rule": "Between the two screws from the front: as far apart as the foot allows, so they share the shelf's pull" },
5852
+ "nut_pitch": { "value": 12, "unit": "mm", "rule": "Between the two nuts' slots, inside the front screws' counterbores with plastic between" },
5853
+ "fillet": { "value": 4, "unit": "mm", "rule": "The 45° fillet in the inside corner between the web and the foot, so the corner is not square" },
5854
+ "nut_floor": { "value": "x1c.layer * 6", "unit": "mm", "rule": "Plastic between the foot's back and the nut's slot" }
5855
+ },
5856
+ "anchors": {
5857
+ "pilot": { "at": ["pitch / 2", "foot", "at"], "axis": [0, 1, 0] },
5858
+ "insert": { "at": ["0 - pitch / 2", "foot", "at"], "axis": [0, 1, 0] },
5859
+ "nut1": { "at": ["nut_pitch / 2", 0, "at"], "axis": [0, -1, 0] },
5860
+ "nut2": { "at": ["0 - nut_pitch / 2", 0, "at"], "axis": [0, -1, 0] },
5861
+ "shelf": { "at": ["wide / 2", "reach - 10", "web / 2"], "axis": [0, 0, 1] }
5862
+ }
5863
+ }
5864
+ ```
5865
+
5866
+ The anchors are where the screws go: `pilot` and `insert` on the foot's front face, over the two front screws' holes,
5867
+ and `nut1` and `nut2` on its back, where the screws from behind come in. `shelf` is where the shelf's weight is hung.
5868
+
5869
+ ```js projects/fix/objects/bracket.js
5870
+ // A shelf bracket, drawn as it prints: the web flat on the bed, the foot standing up along its back edge.
5871
+ // Two cap screws go down counterbores in the foot into the wall plate; two more come from behind the plate into nuts
5872
+ // dropped into slots in the foot.
5873
+ import jscad from '@jscad/modeling'
5874
+ const { polygon, cuboid } = jscad.primitives
5875
+ const { extrudeLinear } = jscad.extrusions
5876
+ const { transform, translate } = jscad.transforms
5877
+
5878
+ // (a profile drawn in y and z, extruded along x)
5879
+ const alongX = (g) => transform([0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1], g)
5880
+
5881
+ export function main (v) {
5882
+ const f = v.fixings, half = v.wide / 2
5883
+ const web = extrudeLinear({ height: v.web }, polygon({ points: [[0 - half, 0], [half, 0], [half, v.reach], [0 - half, v.heel]] }))
5884
+ const foot = cuboid({ size: [v.wide, v.foot, v.out], center: [0, v.foot / 2, v.out / 2] })
5885
+ const fillet = translate([0 - half, 0, 0], alongX(extrudeLinear({ height: v.wide }, polygon({ points: [[v.foot, v.web], [v.foot + v.fillet, v.web], [v.foot, v.web + v.fillet]] }))))
5886
+ const trap = f.nutTrapModel('M3', { axis: 'y', into: '-z', depth: v.out - v.at })
5887
+ return v.ops.subtract(v.ops.union(web, foot, fillet),
5888
+ ...[-1, 1].map((s) => f.counterbore('M3 cap', { length: v.foot, thickness: v.foot, into: '-y', at: [s * v.pitch / 2, v.foot, v.at] })),
5889
+ ...[-1, 1].flatMap((s) => [f.hole('M3', { depth: v.foot, into: '+y', at: [s * v.nut_pitch / 2, 0, v.at] }),
5890
+ f.nutTrap('M3', { axis: 'y', into: '-z', depth: v.out - v.at, at: [s * v.nut_pitch / 2, v.nut_floor + trap.gap / 2, v.out] })]))
5891
+ }
5892
+ ```
5893
+
5894
+ `nutTrapModel` gives the slot's numbers before it is cut: its `gap` along the screw puts the nut's middle where the
5895
+ slot is drawn, so the nut sits `nut_floor` in from the foot's back whatever the printer's slip.
5896
+
5897
+ ```sh
5898
+ npx cad check fix/plate
5899
+ npx cad check fix/bracket
5900
+ ```
5901
+
5902
+ Each prints without supports: no overhang past 45°, no ledge, nothing in mid-air, one piece, a plain first layer. Each
5903
+ seat says what it was drawn to and the rule it rests on: the pilot 2.9 mm from `x1c.pilot_m3` (measured on this
5904
+ printer), the insert's hole 4 mm from `m3.insert_hole` (a community figure, as drawn), each clearance hole 3.5 mm
5905
+ (`m3.clearance`, from ISO 273, plus `x1c.hole_comp`), the counterbore 6 mm by 3 mm, the countersink 6.82 mm at 90°, and
5906
+ the nut's slot 5.7 mm across the flats and 2.6 mm along the screw (`m3.nut_flats` and `m3.nut_height`, plus
5907
+ `x1c.hole_comp` and `x1c.slip`).
5908
+
5909
+ ### Screwed together
5910
+
5911
+ The plate's back is the wall, at z = 0, and up the wall is y. The bracket is turned from how it prints to how it hangs,
5912
+ and stands on the posts. Two `fasten` relations hold it: two cap screws from the front, through the bracket into the
5913
+ plate, and two countersunk screws from behind, through the plate into the bracket's nuts. Neither names a length: the
5914
+ check chooses the shortest sold that fits each screw. The shelf is 2 kg hung at the `shelf` anchor, and gravity runs
5915
+ down the wall.
5916
+
5917
+ ```json projects/fix/assemblies/shelf.json
5918
+ {
5919
+ "$schema": "https://jonibach.github.io/rulecad/schemas/assembly.schema.json",
5920
+ "title": "A shelf bracket on its wall plate",
5921
+ "kind": "fit",
5922
+ "description": "The plate's back on the wall (z = 0), the bracket on its four posts, up the wall along y. Two cap screws go through the bracket's foot into the plate, one into a pilot and one into a heat-set insert; two countersunk screws come from behind the plate into nuts in the foot.",
5923
+ "items": [
5924
+ { "id": "plate", "object": "plate" },
5925
+ { "id": "bracket", "object": "bracket", "rotate": [90, 0, 90], "at": ["0 - bracket.at", 0, "plate.thick + plate.stand"] }
5926
+ ],
5927
+ "fits": [
5928
+ { "a": "bracket", "b": "plate", "min": 0, "max": 0.05, "note": "The foot sits on the plate's posts" }
5929
+ ],
5930
+ "fasten": [
5931
+ { "screw": "M3 cap", "through": ["bracket"], "into": "plate", "at": ["bracket.pilot", "bracket.insert"], "note": "Front screws" },
5932
+ { "screw": "M3 countersunk", "through": ["plate"], "into": "bracket", "at": ["bracket.nut1", "bracket.nut2"], "nut": true, "torque": 0.3, "note": "Back screws" }
5933
+ ],
5934
+ "gravity": [0, -1, 0],
5935
+ "loads": [
5936
+ { "mass": 2, "at": "bracket.shelf", "note": "A shelf and what stands on it" }
5937
+ ]
5938
+ }
5939
+ ```
5940
+
5941
+ ```sh
5942
+ npx cad check fix/shelf
5943
+ npx cad list fix/shelf
5944
+ npx cad order fix/shelf
5945
+ ```
5946
+
5947
+ What the check says, screw by screw:
5948
+
5949
+ - `fasten.holes`: each screw has one axis from under its head through the part it passes into the part it ends in.
5950
+ - `fasten.clearance`: the bracket's and the plate's holes measure 3.5 mm, an M3 clearance hole as drawn.
5951
+ - `fasten.end`: the top front screw ends in a pilot, 2.9 mm and 8.8 mm deep; the bottom one in an insert's hole, 4 mm
5952
+ and 6.7 mm deep; each back screw in an M3 hex nut in its seat in the bracket, 5.7 mm across the flats for the nut's
5953
+ 5.5 mm. The slot is found where it crosses the screw, and the nut drawn there, flats to the slot's walls.
5954
+ - `fasten.length`: M3x10 cap for the pilot (3.4 mm under the head and 6.6 mm into the plate, 1.2 mm short of
5955
+ bottoming out), M3x8 cap for the insert, M3x16 countersunk for the nuts.
5956
+ - `fasten.engagement`: 6.6 mm of thread in PLA where `m3.pilot_depth` asks 5 mm; 4.6 mm in the insert, where
5957
+ `fixings.insert_engagement` asks a diameter or the whole insert; the nut's whole 2.4 mm.
5958
+ - `fasten.seat`: the cap heads sit flat, 3 mm down their counterbores, and PLA under them takes 553 N, a tightening
5959
+ of 0.33 N m; the countersunk heads sit in an 89.8° countersink, flush with the back.
5960
+ - `fasten.access`: a 2.5 mm hex key reaches each cap head along its axis, and a 2 mm key each countersunk head, with
5961
+ nothing within the key's corners for its long arm's 58.5 mm or 52 mm (`hexkey`, ISO 2936).
5962
+ - `fasten.load`: with the shelf's 2 kg, the front screws hold 41.4 times the load, the pilot's thread in PLA first;
5963
+ the back screws 32.6 times, the screw first (the nut's thread is steel and not checked). Each holds its shear by
5964
+ friction 9.5 and 3.6 times over. The torque on the back screws is given (0.3 N m), because the check holds the
5965
+ pressure under a flat seat and not yet on a countersink's cone.
5966
+
5967
+ Each relation is reckoned as if it held the bracket alone, so the two figures are each the worst case. They rest on
5968
+ estimates (the plastic's strength in shear, the nut factor, the friction), and the finding names each one.
5969
+
5970
+ `cad list` gives the screws by thread, length and head, with what they weigh and how they are bought, and the two
5971
+ prints: the plate 5.9 g and the bracket 11.8 g, 17.7 g and about 20 minutes of printing, and 5 g of fixings.
5972
+ `cad order` gives the steps: the plate first, then the bracket with its four screws, each with its key and torque, the
5973
+ insert and the nuts named with them.
5974
+
5975
+ ### Strong enough, and small
5976
+
5977
+ The design rule is the smallest part that carries its load about twice over. By hand, PLA at 39 MPa along the layers
5978
+ (`pla.strength`, a community figure), 2 kg is 19.6 N:
5979
+
5980
+ | Part | Where it is worst | Load | Stress | Margin |
5981
+ |---|---|---|---|---|
5982
+ | Bracket's web | At the foot, 23.6 mm in from the shelf's weight, a section 44 mm deep and 3 mm thick | 463 N mm | 0.48 MPa | 81 times |
5983
+ | Plate | At the lowest post, 19 mm above its bottom edge, which bears on the wall; the top wall screw pulls 780 / 64 = 12.2 N | 232 N mm | 7.7 MPa | 5 times |
5984
+ | Front screws | `fasten.load` | 16.3 N of pull | | 41.4 times |
5985
+ | Back screws | `fasten.load` | 65.2 N of pull | | 32.6 times |
5986
+
5987
+ The web's section modulus is 3 × 44² / 6 = 968 mm³ and the plate's 20 × 3² / 6 = 30 mm³; each stress is the moment
5988
+ over it. The web is stressed along its layers, since it lies flat as it prints. The plate is the part the load sizes:
5989
+ its 3 mm is the least that holds the wall screws' countersinks, and carries the shelf five times. The bracket is sized
5990
+ by its fixings, not its load: room for a head and its key, a nut's slot with plastic round it, and four screws far
5991
+ enough apart to share the pull. A thinner web would still carry the shelf, and would flap.
5992
+
5993
+ ### Two mistakes, caught
5994
+
5995
+ A screw too short. The front screws named as M3x6 by hand:
5996
+
5997
+ ```json projects/fix/assemblies/short.json
5998
+ {
5999
+ "$schema": "https://jonibach.github.io/rulecad/schemas/assembly.schema.json",
6000
+ "title": "The shelf bracket on front screws too short",
6001
+ "kind": "fit",
6002
+ "items": [
6003
+ { "id": "plate", "object": "plate" },
6004
+ { "id": "bracket", "object": "bracket", "rotate": [90, 0, 90], "at": ["0 - bracket.at", 0, "plate.thick + plate.stand"] }
6005
+ ],
6006
+ "fits": [
6007
+ { "a": "bracket", "b": "plate", "min": 0, "max": 0.05, "note": "The foot sits on the plate's posts" }
6008
+ ],
6009
+ "fasten": [
6010
+ { "screw": "M3x6 cap", "through": ["bracket"], "into": "plate", "at": ["bracket.pilot", "bracket.insert"], "note": "Front screws" },
6011
+ { "screw": "M3 countersunk", "through": ["plate"], "into": "bracket", "at": ["bracket.nut1", "bracket.nut2"], "nut": true, "torque": 0.3, "note": "Back screws" }
6012
+ ]
6013
+ }
6014
+ ```
6015
+
6016
+ `npx cad check fix/short` fails, and says what would do:
6017
+
6018
+ ```text
6019
+ ✗ Front screws, screw 1 (bracket.pilot): M3x6 cap engages 2.6 mm of thread in pla (a plastic), 5.2 turns, where m3.pilot_depth asks 5 mm: M3x10 cap would do
6020
+ ✗ Front screws, screw 2 (bracket.insert): M3x6 cap engages 2.6 mm of thread in the insert, 5.7 mm long, 5.2 turns, where fixings.insert_engagement asks a diameter of thread or the whole insert, 3 mm: M3x8 cap would do
6021
+ ```
6022
+
6023
+ A screw that cannot be reached. Shelves usually go up plate first: screw the plate to the wall, then hang the bracket
6024
+ on it. With the wall in the assembly, drawn faint and never printed, and the plate fastened to it:
6025
+
6026
+ ```json projects/fix/objects/wall.json
6027
+ {
6028
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
6029
+ "name": "wall",
6030
+ "title": "A patch of wall",
6031
+ "version": "0.1.0",
6032
+ "role": "reference",
6033
+ "variables": {
6034
+ "size": { "value": 120, "unit": "mm", "rule": "A patch of wall round the plate" },
6035
+ "deep": { "value": 20, "unit": "mm", "rule": "Enough to show where it is" }
6036
+ }
6037
+ }
6038
+ ```
6039
+
6040
+ ```js projects/fix/objects/wall.js
6041
+ // The wall the plate goes on: a reference, drawn faint and never printed. Its face is z = 0.
6042
+ import jscad from '@jscad/modeling'
6043
+ const { cuboid } = jscad.primitives
6044
+
6045
+ export function main (v) {
6046
+ return cuboid({ size: [v.size, v.size, v.deep], center: [0, 0, 0 - v.deep / 2] })
6047
+ }
6048
+ ```
6049
+
6050
+ ```json projects/fix/assemblies/wall-first.json
6051
+ {
6052
+ "$schema": "https://jonibach.github.io/rulecad/schemas/assembly.schema.json",
6053
+ "title": "The plate on the wall first",
6054
+ "kind": "fit",
6055
+ "items": [
6056
+ { "id": "wall", "object": "wall" },
6057
+ { "id": "plate", "object": "plate" },
6058
+ { "id": "bracket", "object": "bracket", "rotate": [90, 0, 90], "at": ["0 - bracket.at", 0, "plate.thick + plate.stand"] }
6059
+ ],
6060
+ "fits": [
6061
+ { "a": "plate", "b": "wall", "fastens": true, "min": 0, "note": "The plate on the wall, on two wall screws" },
6062
+ { "a": "bracket", "b": "plate", "min": 0, "max": 0.05, "note": "The foot sits on the plate's posts" }
6063
+ ],
6064
+ "fasten": [
6065
+ { "screw": "M3 cap", "through": ["bracket"], "into": "plate", "at": ["bracket.pilot", "bracket.insert"], "note": "Front screws" },
6066
+ { "screw": "M3 countersunk", "through": ["plate"], "into": "bracket", "at": ["bracket.nut1", "bracket.nut2"], "nut": true, "torque": 0.3, "note": "Back screws" }
6067
+ ]
6068
+ }
6069
+ ```
6070
+
6071
+ `npx cad check fix/wall-first` fails on the back screws and on the order, naming the wall:
6072
+
6073
+ ```text
6074
+ ✗ Back screws, 2 M3 countersunk screws: a 2 mm hex key cannot reach the head: wall stands over it, 0.05 mm up the screw's axis and goes on first (The plate on the wall, on two wall screws), and a ball-end key tilted 25° does not clear it either. Move the screw, open a way through wall, or fit wall after
6075
+ ✗ the screw of "Back screws" can't be reached in any order: wall stands over it and goes on first (The plate on the wall, on two wall screws)
6076
+ ```
6077
+
6078
+ So this bracket goes on its plate at the bench, and the plate then goes on the wall: its wall screws are clear of the
6079
+ foot, and `cad order fix/shelf` builds it in that order. The other way to hang it plate first is to bring every screw
6080
+ in from the front: four front screws into pilots or inserts, and no nut.
6081
+
6082
+ ### The build page
6083
+
6084
+ `npx cad link fix/shelf --md` gives a link to the model page. Since the assembly has a `fasten`, the link carries a build
6085
+ page: the prints with their grams and time, a Fasteners table (each screw, nut and insert, how many, their grams, and
6086
+ the packs to buy with what is spare), and the steps of `cad order`, each with its screws, the key and the torque to
6087
+ tighten to. The screws, the insert and the nuts are drawn faint in place.
6088
+
6089
+ ### What is measured, and what waits on the bench
6090
+
6091
+ The pilot is the X1C's own measured figure. The insert's hole, the nut's slot, the counterbore's room for a head and
6092
+ the strength figures under `fasten.load` are not, and their findings say so. Print 7 in
6093
+ `examples/bench/projects/benchmarks/MEASURE.md`, the fixings coupon, settles them: pilots at five sizes, insert holes,
6094
+ nut pockets and slots at three fits, a counterbore and printed threads. Its results go back with `cad measured
6095
+ benchmarks/fixings-test <rule>=<figure>`, and every design drawn from `v.fixings` follows them the next time it is
6096
+ built.
package/README.md CHANGED
@@ -157,6 +157,13 @@ own copy anywhere and name it in `viewUrl`.
157
157
  strain at a travel, and `printable(shape, printer, material, model)` for how it prints. Drawn flat: bending along y,
158
158
  width up z, so a flexure bends within its layers.
159
159
  - `v.motors`: motors (`@rulecad/motors`): `motorModel`, `mount` and `bore` for the holes a part needs round a motor and its shaft, `performance` for its torque and speed. In an assembly a motor is an item (see Motors).
160
+ - `v.fixings`: screws, nuts and inserts (`@rulecad/fixings`), bound to the project: `hole('M3', { kind: 'pilot', at })`
161
+ for a hole sized by what it is for, `counterbore`, `countersink`, `nutPocket`, `nutTrap`, `squareNutSlot` and
162
+ `insertBoss` for seats, `screw`, `nut`, `washer` and `insert` as light reference solids, `thread` for one cut to
163
+ print, and `engagement`, `seating` and `lengthFor` for first sums. Each reads the workspace's own thread set
164
+ (`rules/m3.json`) before the kit's, the project's printer and (for what a thread is in) its material, so a design
165
+ types no diameter and passes none. `cad check` lists what each call drew and the rule it rests on (`hole.drawn`,
166
+ `counterbore.drawn`, ...). A design may also import `@rulecad/fixings` itself: then it reads the kit's sets only.
160
167
  - `v.gears`: gears (`@rulecad/gears`): `spur`, `rack` and `internal` as shapes, from a module and teeth, each with its
161
168
  model (`gearModel`, `rackModel`, `internalModel`) and `printable(model, printer, width)`. Drawn flat: the axis up z,
162
169
  the first tooth on +x, the face on the bed. Two gears in an assembly mesh with a joint's `mesh` (see Joints).
@@ -274,7 +281,7 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
274
281
  can't write or delete files, start programs or workers, or load addons, and it reads only the workspace and the
275
282
  packages designs use, by their real paths (a `node_modules` link spelled through another link, as macOS spells its
276
283
  temporary folders through `/tmp` and `/var`, is refused by name: make the link with the real path). To keep it to making shapes it may import only `@jscad/modeling`, `@rulecad/shapes`,
277
- `@rulecad/flexures`, `@rulecad/gears` and files in its own project (no `node:` modules), `fetch` and its kin are gone, and it is
284
+ `@rulecad/flexures`, `@rulecad/gears`, `@rulecad/motors`, `@rulecad/fixings` and files in its own project (no `node:` modules), `fetch` and its kin are gone, and it is
278
285
  started with none of your environment (no tokens). Those shut the ordinary roads to the network, not every one:
279
286
  before Node 25 the permission model doesn't cover the network, so a design written to get round them might still
280
287
  reach it. Run only designs you trust. It gets its values as data and returns its parts; what it prints
@@ -323,6 +330,57 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
323
330
  - `check`, `preview` (`--explode` lifts each kind of object above the last: plate, switches, keycaps), `show`, `link` and, for plates, `export` all take
324
331
  `<project>/<assembly>`.
325
332
 
333
+ ### Screwed joints: `fasten`
334
+
335
+ A joint held by screws is one relation, and it knows the screw:
336
+
337
+ ```json
338
+ "fasten": [
339
+ { "screw": "M3 cap", "through": ["bracket"], "into": "base", "at": ["bracket.h1", "bracket.h2"] },
340
+ { "screw": "M3x16 cap", "through": ["cover", "frame"], "into": "frame-back", "holes": "cover.body", "nut": true, "washer": true }
341
+ ]
342
+ ```
343
+
344
+ `screw` names the thread and head as `@rulecad/fixings` reads them (`M3 cap`, `M4 button`, `M3x12 countersunk`,
345
+ `6-32 UNC cap`). `through` lists the parts the screw passes, in order from under its head, and `into` is the part it
346
+ ends in. The screws' places are given one of two ways: `at`, an anchor on each screw's axis (a point on the hole's
347
+ centre line, the anchor's axis along the screw), or `holes`, a part whose own round holes are the places (for a
348
+ circuit board, its mounting holes). `nut` (`true`, `hex`, `square` or `lock`) says a nut holds the screw where the
349
+ last part does not; `washer` puts a plain washer under the head; `length` gives the length where the name has none;
350
+ `torque` gives the tightening torque in N m. Add one with `cad add fasten <project>/<assembly> --screw "M3 cap"
351
+ --through bracket --into base --at bracket.h1,bracket.h2`.
352
+
353
+ Nothing about the holes is declared. Each part is read as drawn: along the screw's axis the mesh is sliced, and the
354
+ outline round the axis gives the hole's centre, its diameter (across its corners, as it was drawn) and where it
355
+ starts and stops. From that the check says:
356
+
357
+ | Finding | What it checks |
358
+ |---|---|
359
+ | `fasten.holes` | One axis runs from under the head through every part: a hole 0.05 mm or more off it fails, with the distance |
360
+ | `fasten.clearance` | Each part passed through has a clearance hole for the thread as drawn on this printer, between the close and the loose figure; it says what the hole measures and what it should be |
361
+ | `fasten.end` | The far end is a pilot, a hole to tap, a thread drawn to print, an insert's hole or a nut's seat of this thread (a pocket on the far face, or a slot across the screw partway along it, as `v.fixings.nutTrap` cuts), or a clearance hole with `nut`; into a motor, one of its own threaded mounting holes |
362
+ | `fasten.length` | The length chosen where none is given: the shortest sold length that fits the stack as measured (into a motor, the longest that stops short of the end of its thread). A given length is checked for reaching the far end, bottoming out in a blind hole (1 mm is kept at the tip) and standing more than a diameter proud |
363
+ | `fasten.engagement` | The thread engaged at the far end against the rule for what it is in: the thread's `pilot_depth` or the engagement rule for the project's material, an insert's length, a nut's height. A short one names the length or the depth that would do |
364
+ | `fasten.seat` | The head (or its washer) has a flat seat as wide as itself and square to the screw, read under the head from the part; a countersunk head has a countersink of its angle. It says the force and torque the seat takes on the project's material, and with `torque` holds the pressure against the material's strength and names the washer that would bring it within |
365
+ | `fasten.access` | A key or driver reaches the head along its axis, in the build pose: a cylinder as wide as the key across its corners, as long as its long arm (both from the `hexkey` set, ISO 2936; a hexagon head's socket adds `hexkey.socket_wall`, an estimate), clear of every other part. A part over the head that goes on after the screw passes, with the step it goes on at: `cad order` puts it after. One that must be there first (it comes earlier in the order, it is one of the joined parts, or it is no step at all) fails by name with how far over the head it is; where a ball-end key tilted up to `hexkey.ball_end_tilt` (25°) clears it, it warns instead |
366
+ | `fasten.load` | With `loads` or a motor's torque on the joint: what it holds up (the parts left with no other way to the first item, their masses, the loads hung on them, under the assembly's `gravity`, and the torque of a motor among them), shared between the screws as a group (`screwGroup` of `@rulecad/fixings`: shear by distance from the centroid, pull by a plane through it). The screw that takes the most is held against its proof load, the thread it is in against stripping, and the clamp against slipping, at its preload (`screwLoad`); the margin is how many times the load it holds, and under 2 it warns. With no `torque`, it says the torque that leaves the thread twice the load, within the seat, and `cad order` tightens to that. It names the estimates it rests on (the nut factor, a plastic's shear strength, the friction) |
367
+
368
+ Every finding has `at` (under the head) and `between` (head to tip), so the viewer points at the screw. The screws,
369
+ nuts, washers and inserts are placed as reference parts from `@rulecad/fixings`: faint in previews, lifted along
370
+ their own axes by `--explode`, checked for overlap with everything but what they are threaded into, moving with the
371
+ part they sit in through every pose, and carried in links. `cad list` counts them and `cad order` names them on the
372
+ step. A `fasten` holds its parts as a fit with `"fastens": true` does and lines their holes up as a holes fit does;
373
+ both older forms still work, and an assembly with no `fasten` checks as before.
374
+
375
+ `cad list` counts every fixing (`fasten.count`): each screw, nut, washer and insert a `fasten` placed (a component's
376
+ too), a motor's mounting screws where a fit that `fastens` holds it (as many as its holes, at the length its mount
377
+ works out for the plate as drawn, taken to a length sold), and a fit that names its `fastener` by hand. They are
378
+ summed by name, which is the thread, length and head (`12 × M3x8 cap`), each with its mass (an estimate from its
379
+ outline, from `@rulecad/fixings`) and the line's, and rounded up to whole packs of `packs.pack` (10, an estimate:
380
+ set your own in `rules/packs.json`) with the spares said. `--json` gives each line as `{ fastener, qty, kind,
381
+ thread, length, head, grams, mass, packs, buy, spare, from }`, the totals add `fixingsGrams` to the machine's mass,
382
+ and the build page's list shows the same.
383
+
326
384
  ### Joints and poses
327
385
 
328
386
  Things that move (a lid, a hinged screen, a drawer, a ball head) are one assembly with joints, not one assembly per
@@ -427,11 +485,11 @@ An item can be a motor instead of a printed object: `{ "id": "drive", "motor": {
427
485
 
428
486
  Once an assembly is checked, these say how to make it. They all read the assembly itself, so they can't disagree with it.
429
487
 
430
- - `cad order <project>/<assembly>`: the order it goes together in, each step with the part and the fasteners named from its `fastens` notes (`"fastener": "M3x12", "count": 2` on a fit puts them on the shopping list and the step). `--preview` writes a picture of each step to `.preview/`: what's there, and the new part held off along the way it goes on. The order is found by taking the assembly apart, so a part goes in after what it's fastened into, a bearing before its shaft, and a nut trapped by a wall before the neighbour that traps it. A part goes on along a straight line that clears everything already there; which line comes from the part as drawn.
488
+ - `cad order <project>/<assembly>`: the order it goes together in, each step with the part and the fasteners named from its `fastens` notes (`"fastener": "M3x12", "count": 2` on a fit puts them on the shopping list and the step). A `fasten` names its screws on the step where its parts are both there, with the key that turns them and how tight: its `torque`, or the most the seat under the head takes (`2. bracket goes on: bracket fastened to base (2 × M3x10 cap) with a 2.5 mm hex key, to 0.33 N m at most (what the seat takes)`); `--json` gives each as `{ fit, fastener, count, key, tighten: { torque, given } }`, and the build page shows the same. `--preview` writes a picture of each step to `.preview/`: what's there, and the new part held off along the way it goes on. The order is found by taking the assembly apart, so a part goes in after what it's fastened into, a bearing before its shaft, and a nut trapped by a wall before the neighbour that traps it. A part goes on along a straight line that clears everything already there; which line comes from the part as drawn.
431
489
  - `assembly.order` is `cad check`'s finding on it: a part no order can reach fails by name, and a part sealed inside another too. A fit can say where a screw is driven from with `"access": "<item>.<anchor>"`, the anchor's z pointing out along the screw: whatever stands on that line goes on after the screw, and if it has to go on first the screw can't be reached at all. Works on an assembly's own items; a component (an assembly used as an item) goes on as one step.
432
490
  - `cad plates <project>/<assembly>`: every printed part laid out on beds, in its print orientation (as it's drawn), grouped by filament so each plate is one colour change, spaced by the first layer's rule (the printer's `print_gap` plus twice its `foot`, up to whole lines; `--gap` for your own). They're written as `kind: "plate"` assemblies called `<assembly>-<filament>-<n>` and checked as prints; `cad export` makes each one's 3MF. Each plate remembers what's on it by its build's hash (`"packed"` in its file): a changed part re-packs only its plate, so the other plates keep their files untouched, and a part too big for the bed is said by name (`plate.bed`).
433
491
  - `cad wires <project>/<assembly>`: the wiring sheet, printed and written to `exports/<project>/<assembly>.wiring.md` (`cad machine` writes it too): each wire's length through every pose with its service loop, gauge, colour, connectors and board pins. Wires also show faint along their routes in `cad preview` and in the link, moving with the joints, and are never parts: no overlap check sees them.
434
- - `cad link` for such an assembly carries the rest of the project with the model. A **Build** button on the page opens, beside it, the shopping list, the plates drawn on their beds, the wiring sheet, the assembly steps (each shows the model at that step) and the machine's settings. The Rules panel lists **predicted against measured**: the ledger `cad measured` writes, each with its ratio, and what the checks predict that nobody has measured yet.
492
+ - `cad link` for such an assembly (or one with a `fasten`) carries the rest of the project with the model. A **Build** button on the page opens, beside it, the shopping list, the plates drawn on their beds, the wiring sheet, the assembly steps (each shows the model at that step) and the machine's settings. The Rules panel lists **predicted against measured**: the ledger `cad measured` writes, each with its ratio, and what the checks predict that nobody has measured yet.
435
493
  - A link for an assembly with a `task` lets the page move the machine: see "Things that move" in the viewer's README. It carries the newest step file `cad plot` wrote for this assembly (`--steps <file>` for another, `--no-steps` for none). A step file for other joints is refused by name.
436
494
 
437
495
  ## Optimised parts
package/bin/cad.mjs CHANGED
@@ -53,6 +53,9 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
53
53
  cad values <project>/<object> [names…] the object's variables, resolved [--json]
54
54
  cad set <project>/<object> name=value … change variables, keeping the file's layout [--unit, --rule, --label, --new to add one]
55
55
  cad add fit|joint|item|loop|pose <project>/<assembly> --a … --b … --min … add to an assembly, keeping its layout
56
+ cad add fasten <project>/<assembly> --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2
57
+ a screwed joint (or --holes bracket.body for the part's own holes) [--nut [hex|square|lock]]
58
+ [--washer] [--length 12] [--torque 0.5] [--note …]
56
59
  cad why <project>/<object>.<name> what a value reads, down to the rules and their sources [--json] [--depth N]
57
60
  cad check <project>/<object> raw numbers in the design, then printability (exit 1 on a failure) [--json: findings as data]
58
61
  cad preview <project>/<object> six views as a PNG in .preview/ (prints the path); an assembly with a motor also gets
@@ -88,12 +91,14 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
88
91
  .preview/, and any stroke refused [--calibrate: the calibration drawing] [--tol 0.1] [--json]
89
92
  cad order <project>/<assembly> the order it goes together in, each step with its fasteners [--preview: an exploded picture of each step in .preview/]
90
93
  cad plates <project>/<assembly> every printed part on beds, by filament, spaced by the first-layer rule: written as plate assemblies and checked; a changed part re-packs only its plate [--gap mm] [--json]
91
- cad list <project>/<assembly> what it takes to build: bought parts by set, fasteners, wire, printed parts in grams
94
+ cad list <project>/<assembly> what it takes to build: bought parts by set, every screw, nut and insert in packs, wire, printed parts in grams
92
95
  cad wires <project>/<assembly> the wiring sheet: each wire's length, gauge and ends, written to exports/ [--out wiring.md]
93
96
  cad measured <project>/<assembly> <name>=<value> … a measurement, where the estimate was: a rule (x1c.press=0.08) or a
94
97
  check's prediction (task.accuracy=0.8): says what moved, and keeps a ledger of predicted
95
98
  against measured, shown by cad history [--unit mm] [--source "how"] [--rule "what it is"]
96
99
  [--table: what the assembly still assumes, as Markdown; --out MEASURE.md: kept in that file]
100
+ The fixings coupon's rules need no --rule: x1c.pilot_m4, x1c.insert_m3 (and _petg for one
101
+ plastic), x1c.nut_fit, x1c.nut_slip, x1c.thread_gap, x1c.thread_flank (45 or 60)
97
102
  cad measure <model.stl|3mf> a model from elsewhere, measured: size, the stretches along its length with the same
98
103
  cross-section, and each section's shape, with a drawing in .preview/measure/
99
104
  [--along x|y|z] [--at 10,50: sections there too] [--line 0.6,2.5;4.6,2.5: where lines
@@ -123,22 +128,23 @@ const OPTIONS = ['table', 'calibrate', 'check', 'turns', 'preview', 'gap', 'no-s
123
128
  'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
124
129
  'sweep', 'tol', 'trailer', 'ttl', 'version', 'watch', 'line',
125
130
  'unit', 'rule', 'label', 'from', 'out', // cad set, cad rules
126
- 'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate']; // cad add
131
+ 'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate', // cad add
132
+ 'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque']; // cad add fasten
127
133
  // What a command takes, where that isn't <project>/<object>
128
- const USAGE = { add: 'fit|joint|item|loop|pose <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
134
+ const USAGE = { add: 'fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
129
135
  optimise: '<project>/<problem>', optimize: '<project>/<problem>', history: '<project>[/<object>]', release: '<project>[/<object>] -m "what changed"',
130
136
  diff: '<project>/<object> <from> [<to>]', compare: '<project>/<object> <a> <b>', match: '<project>/<object> <model.stl|model.3mf>', clone: '<board.kicad_pcb | GitHub link> <name>' };
131
137
 
132
138
  const args = process.argv.slice(2);
133
139
  // Options that stand alone. Every other takes the value after it: --name value, or -m for one-letter names
134
- // (--sweep and --watch take one or not).
135
- const FLAGS = ['table', 'calibrate', 'check', 'preview', 'no-steps', 'all', 'dry-run', 'explode', 'force', 'fresh', 'json', 'long', 'md', 'new', 'no-models', 'no-pictures', 'no-rules', 'open', 'progress', 'push', 'short'];
140
+ // (--sweep, --watch and --nut take one or not).
141
+ const FLAGS = ['table', 'calibrate', 'check', 'preview', 'no-steps', 'all', 'dry-run', 'explode', 'force', 'fresh', 'json', 'long', 'md', 'new', 'no-models', 'no-pictures', 'no-rules', 'open', 'progress', 'push', 'short', 'washer'];
136
142
  const opt = (k) => {
137
143
  const i = args.findIndex((a) => a === `--${k}` || (k.length === 1 && a === `-${k}`));
138
144
  if (i < 0) return undefined;
139
145
  if (FLAGS.includes(k)) return true;
140
146
  if (args[i + 1] && !args[i + 1].startsWith('--')) return args[i + 1];
141
- if (['sweep', 'watch'].includes(k)) return true;
147
+ if (['sweep', 'watch', 'nut'].includes(k)) return true;
142
148
  throw new Error(`${args[i]} needs a value after it`);
143
149
  };
144
150
  // The arguments that aren't options or an option's value: cad values keyboard/case depth width --json
@@ -489,6 +495,7 @@ async function main() {
489
495
  ? [{ level: 'pass', text: `a reference (${(await import('@rulecad/printcheck')).bounds(b.triangles).size.map(fmt).join(' × ')} mm), not printed: no print checks`, code: 'print.reference' }]
490
496
  : check(b.triangles, printer(b, d), { parts: b.parts })),
491
497
  ...(b.mechanism?.findings || []), // a lamina mechanism's own: it prints free, stops, holds, clears in every state
498
+ ...(b.fixings || []), // what v.fixings drew: each hole and seat, what it was drawn to and the rule it rests on
492
499
  ...(await analyses(b, d, tag)),
493
500
  ], { object: `${d.project}/${d.name}`, title, version, ...(Object.keys(set).length ? { set } : {}), orientation: b.object.orientation, parts: b.parts.map((p) => ({ name: p.name, role: p.role || 'part' })) });
494
501
  if (b.object.orientation) say(` orientation: ${b.object.orientation}`);
@@ -560,7 +567,7 @@ async function editVariables(ref) {
560
567
  console.log(`set ${r.changed.join(', ')} in ${path.relative(WS, r.file)}`);
561
568
  }
562
569
 
563
- // cad add fit|joint|item|loop|pose <project>/<assembly> --key value …: add to an assembly, keeping its layout
570
+ // cad add fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …: add to an assembly, keeping its layout
564
571
  async function editAssembly(what, ref) {
565
572
  const list = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => parseValue(x.trim())) : undefined);
566
573
  const pick = (keys) => Object.fromEntries(keys.map((k) => [k, typeof opt(k) === 'string' ? parseValue(opt(k)) : undefined]).filter(([, v]) => v !== undefined));
@@ -571,11 +578,15 @@ async function editAssembly(what, ref) {
571
578
  else if (what === 'item') entry = { ...text(['id', 'object', 'assembly', 'variant']), ...(list('at') ? { at: list('at') } : {}), ...(list('rotate') ? { rotate: list('rotate') } : {}),
572
579
  ...(typeof opt('set') === 'string' ? { set: Object.fromEntries(sets() && Object.entries(sets()).map(([k, v]) => [k, parseValue(v)])) } : {}) };
573
580
  else if (what === 'loop') entry = text(['a', 'b', 'label']);
581
+ else if (what === 'fasten') { // --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2 | --holes bracket.body [--nut [hex] --washer --length 12 --torque 0.5 --note …]
582
+ const names = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => x.trim()).filter(Boolean) : undefined);
583
+ entry = { ...text(['screw']), through: names('through') ?? [], ...text(['into']), ...(names('at') ? { at: names('at') } : {}), ...text(['holes']), ...(opt('nut') ? { nut: opt('nut') === true ? true : String(opt('nut')) } : {}), ...(opt('washer') ? { washer: true } : {}), ...pick(['length', 'torque']), ...text(['note']) };
584
+ }
574
585
  else if (what === 'pose') {
575
586
  const pairs = positional().slice(3);
576
587
  if (typeof opt('name') !== 'string' || !pairs.length) throw new Error('usage: cad add pose <project>/<assembly> --name open hinge=90 [joint=value …]');
577
588
  entry = { name: opt('name'), values: Object.fromEntries(pairs.map((p) => { const [k, v] = p.split('='); return [k.trim(), v.includes(',') ? v.split(',').map(parseValue) : parseValue(v)]; })) };
578
- } else throw new Error('usage: cad add fit|joint|item|loop|pose <project>/<assembly> --key value …');
589
+ } else throw new Error('usage: cad add fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …');
579
590
  const r = addToAssembly(ref, what, entry);
580
591
  if (opt('json')) return console.log(JSON.stringify({ ...r, added: entry }));
581
592
  console.log(`added ${/^[aeiou]/.test(what) ? "an" : "a"} ${what} to ${path.relative(WS, r.file)}`);