@rulecad/cad 0.7.53 → 0.7.56
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 +20 -7
- package/CHANGELOG.md +108 -0
- package/EXAMPLES.md +579 -267
- package/README.md +106 -12
- package/TUTORIAL.md +25 -15
- package/bin/cad.mjs +79 -25
- package/lib/assembly.mjs +70 -26
- package/lib/beams.mjs +147 -0
- package/lib/bought.mjs +1 -1
- package/lib/buildpage.mjs +6 -3
- package/lib/design.mjs +13 -8
- package/lib/edit.mjs +26 -1
- package/lib/fasten.mjs +72 -15
- package/lib/frames.mjs +63 -0
- package/lib/jsonedit.mjs +19 -0
- package/lib/list.mjs +16 -9
- package/lib/measured.mjs +24 -4
- package/lib/motors.mjs +21 -10
- package/lib/order.mjs +5 -2
- package/lib/profilemeasure.mjs +278 -0
- package/lib/sandbox-hooks.mjs +2 -2
- package/lib/sandbox-run.mjs +3 -2
- package/lib/sandbox.mjs +8 -7
- package/lib/schema.mjs +4 -3
- package/lib/sheet.mjs +160 -4
- package/package.json +8 -6
- package/schemas/assembly.schema.json +37 -11
- package/schemas/object.schema.json +2 -2
- package/schemas/outline.schema.json +24 -0
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ npx cad compare keyboard/keycap dsa legend-f # two variants (or releases) si
|
|
|
43
43
|
npx cad import-kle layout.json keyboard/mine # a layout from keyboard-layout-editor.com, into layouts/
|
|
44
44
|
npx cad clone <github link to a .kicad_pcb> sea_picro # a published board's circuit, into rules/, to redraw by rules
|
|
45
45
|
npx cad measure cover.3mf --rules cover # a model from elsewhere, measured into draft rules
|
|
46
|
+
npx cad measure beam.stl --profile profile-2020-mine # a beam's profile from its maker's model or a DXF of its section
|
|
46
47
|
npx cad match legion-go/rail cover.3mf # how closely a design matches that model, both ways
|
|
47
48
|
```
|
|
48
49
|
|
|
@@ -164,6 +165,10 @@ own copy anywhere and name it in `viewUrl`.
|
|
|
164
165
|
(`rules/m3.json`) before the kit's, the project's printer and (for what a thread is in) its material, so a design
|
|
165
166
|
types no diameter and passes none. `cad check` lists what each call drew and the rule it rests on (`hole.drawn`,
|
|
166
167
|
`counterbore.drawn`, ...). A design may also import `@rulecad/fixings` itself: then it reads the kit's sets only.
|
|
168
|
+
- `v.frames`: beams and profiles (`@rulecad/frames`): `profileModel` for a profile's figures, slots and faces
|
|
169
|
+
(`v.frames.profileModel('2020-misumi-hfs5').slots['slot-6-misumi'].opening`, to draw a tab that drops into a slot),
|
|
170
|
+
`slotModel`, `beamModel`, `beam` and `outline`. A profile measured into this workspace's `rules/` (`cad measure
|
|
171
|
+
--profile`) is read before the kit's, with its outline. In an assembly a beam is an item (see Beams).
|
|
167
172
|
- `v.gears`: gears (`@rulecad/gears`): `spur`, `rack` and `internal` as shapes, from a module and teeth, each with its
|
|
168
173
|
model (`gearModel`, `rackModel`, `internalModel`) and `printable(model, printer, width)`. Drawn flat: the axis up z,
|
|
169
174
|
the first tooth on +x, the face on the bed. Two gears in an assembly mesh with a joint's `mesh` (see Joints).
|
|
@@ -253,6 +258,26 @@ faces) show up as an even offset: set `--tol` above them.
|
|
|
253
258
|
A model's licence limits what you make from it, not what you learn: measurements are facts, but a non-commercial or
|
|
254
259
|
share-alike model's shape shouldn't be copied into a design under another licence. `measure` warns about those.
|
|
255
260
|
|
|
261
|
+
**A beam's profile from its maker's model.** `cad measure <beam.stl|beam.3mf|section.dxf> --profile <name>` reads an
|
|
262
|
+
aluminium extrusion's section and writes it as a profile rule set, for a beam the kit has no set for:
|
|
263
|
+
|
|
264
|
+
```sh
|
|
265
|
+
npx cad measure hfs5-2020.stl --profile profile-2020-mine --source https://example.com/hfs5-2020 --licence "the maker's terms"
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
| It does | How |
|
|
269
|
+
|---|---|
|
|
270
|
+
| Takes the section | From a model: across its longest axis (or `--along y`), in the middle of the longest stretch that keeps one cross-section. From a DXF: its LINE, LWPOLYLINE (with bulges), ARC and CIRCLE entities, joined into closed loops; inches, centimetres and metres are turned into mm. A SPLINE, an ELLIPSE or a block is refused by name: export the section as lines and arcs |
|
|
271
|
+
| Finds each slot | On every face: the opening at its narrowest, the lip's thickness at its tip, the width under the lips, the depth, the floor's width and the flanks' angle, and a V mouth (`track_width`, `track_angle`) where there is one. An opening with no room under lips is told as a groove, or as the channel of a C section |
|
|
272
|
+
| Finds the bores | Round holes at the middles of the cells are the profile's bores; other round holes and hollows are listed, and stay in the outline |
|
|
273
|
+
| Names the slot family | The known family (the kit's, or your workspace's) whose opening, lip, width and depth are all within `--tol` (0.1 mm) of what was found; where none is, a new family is drafted as `rules/slot-<opening>-<name>.json` |
|
|
274
|
+
| Writes | `rules/<name>.json`, a draft profile with every figure `derived` and carrying the source and licence; `rules/outlines/<name>.json`, the section itself; `.preview/measure/<name>-profile.svg` (and `.png`), the section with each slot and bore marked and listed, to check against the bar in hand |
|
|
275
|
+
|
|
276
|
+
Then `cad rules check <name>` and `cad rules draw <name>`, which use the measured outline in place of a drawn one, and
|
|
277
|
+
add what a model cannot say: the maker, the alloy, a material set for its mass, the thread its bore taps to. The
|
|
278
|
+
outline is the model's shape, so it goes into your own workspace and nowhere else: the kit publishes no maker's
|
|
279
|
+
outline, and under a non-commercial, no-derivatives or share-alike licence the command says to keep it there.
|
|
280
|
+
|
|
256
281
|
## Assemblies
|
|
257
282
|
|
|
258
283
|
`projects/<project>/assemblies/<name>.json` places objects together. Positions are expressions over rules and the
|
|
@@ -319,10 +344,16 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
|
|
|
319
344
|
- A fit with `*` applies to every copy: `{ "a": "plate", "b": "key-*.switch.bottom", … }`. With `*` on both sides,
|
|
320
345
|
each copy is checked against every other copy near it: `{ "a": "key-*.cap", "b": "key-*.cap", "min": 0.5 }`. Repeated fits are reported
|
|
321
346
|
together: the worst case, and how many of the copies are in range.
|
|
322
|
-
- **
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
347
|
+
- **Screws** join parts with a `fasten` (the next section), which knows the screw: it follows each one through the
|
|
348
|
+
holes as drawn, chooses its length, and puts it on the shopping list. A gap fit can't see holes: a board that rests on
|
|
349
|
+
its bosses passes even when the bosses are in the wrong place. The older **holes fit** follows a board's mounting
|
|
350
|
+
holes into what they screw into, without the screw: `{ "holes": "pcb.board", "into": "case.body", "depth":
|
|
351
|
+
"m2.insert_length" }`, each path clear for `depth` mm and solid within `ring` mm of it (default: the hole's diameter)
|
|
352
|
+
half way down, `"direction": "up"` for screws from below. Where a holes fit and a fit that `fastens` join the same two
|
|
353
|
+
items, `cad check` says the fasten that would stand for both, with the entry to paste (`fasten.suggest`, a note), and
|
|
354
|
+
`cad add fasten <project>/<assembly> --from-fits` puts it in their place (below). A `fasten` with `"holes": "pcb.board"` holds a
|
|
355
|
+
board's holes to its thread's clearance hole as the fab drills it, with nothing added for a printer (EXAMPLES,
|
|
356
|
+
chapter 6).
|
|
326
357
|
- `requires` pins versions (`^` same major, at least this version, 0.x included, since a minor release never breaks a
|
|
327
358
|
fit here; `~` same minor); an item can use a release: `"object": "keycap@0.2.1"`, or a variant: `"keycap:oem-r3"`.
|
|
328
359
|
- The check names any `estimate` rule an assembly relies on, through its positions or its objects, so guesses get
|
|
@@ -347,7 +378,10 @@ ends in. The screws' places are given one of two ways: `at`, an anchor on each s
|
|
|
347
378
|
centre line, the anchor's axis along the screw), or `holes`, a part whose own round holes are the places (for a
|
|
348
379
|
circuit board, its mounting holes). `nut` (`true`, `hex`, `square` or `lock`) says a nut holds the screw where the
|
|
349
380
|
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.
|
|
381
|
+
`torque` gives the tightening torque in N m. A screw across a yoke or a split clamp ends in the part under its head:
|
|
382
|
+
name that part first in `through` and again as `into` (`"through": ["fork", "block"], "into": "fork", "nut": true`),
|
|
383
|
+
and place each screw with `at`, an anchor whose axis points from the head into the part. Along the axis, the part's
|
|
384
|
+
first stretch of material is the side under the head, and the rest is the far side. Add one with `cad add fasten <project>/<assembly> --screw "M3 cap"
|
|
351
385
|
--through bracket --into base --at bracket.h1,bracket.h2`.
|
|
352
386
|
|
|
353
387
|
Nothing about the holes is declared. Each part is read as drawn: along the screw's axis the mesh is sliced, and the
|
|
@@ -360,7 +394,7 @@ starts and stops. From that the check says:
|
|
|
360
394
|
| `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
395
|
| `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
396
|
| `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 |
|
|
397
|
+
| `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; into a motor, its own thread's depth, and at least one diameter (`engagement.steel`, as `motor.mount` holds it). A short one names the length or the depth that would do |
|
|
364
398
|
| `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
399
|
| `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
400
|
| `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) |
|
|
@@ -372,9 +406,19 @@ part they sit in through every pose, and carried in links. `cad list` counts the
|
|
|
372
406
|
step. A `fasten` holds its parts as a fit with `"fastens": true` does and lines their holes up as a holes fit does;
|
|
373
407
|
both older forms still work, and an assembly with no `fasten` checks as before.
|
|
374
408
|
|
|
409
|
+
**From the older forms.** A holes fit and a fit with `"fastens": true` between the same two items said apart what one
|
|
410
|
+
`fasten` says, and neither knew the screw. `cad check` names the pair in a note (`fasten.suggest`) with the entry to
|
|
411
|
+
paste: `{ "screw": "M2 cap", "through": ["pcb.board"], "into": "case.body", "holes": "pcb.board" }`. The screw is
|
|
412
|
+
read from the fit's `fastener` (`M2x6`), else from a thread set the holes fit's `depth` names (`m2.insert_length`),
|
|
413
|
+
else from the board's holes as drawn: the largest metric thread narrower than the narrowest hole. `cad add fasten
|
|
414
|
+
<project>/<assembly> --from-fits` writes it in their place: the holes fit goes, the fit that fastens keeps its gap
|
|
415
|
+
range (`min`, `max`) with `fastens`, `fastener` and `count` taken off, or goes too where it had no range. `--screw "M2x8
|
|
416
|
+
countersunk"` gives another screw. Screws driven from below (`"direction": "up"`) are left for you to write.
|
|
417
|
+
|
|
375
418
|
`cad list` counts every fixing (`fasten.count`): each screw, nut, washer and insert a `fasten` placed (a component's
|
|
376
419
|
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
|
|
420
|
+
works out for the plate as drawn, taken to a length sold), and a fit that names its `fastener` by hand (pins, a clip:
|
|
421
|
+
anything that is not a screw, since a screw is a `fasten`'s, which knows its length). They are
|
|
378
422
|
summed by name, which is the thread, length and head (`12 × M3x8 cap`), each with its mass (an estimate from its
|
|
379
423
|
outline, from `@rulecad/fixings`) and the line's, and rounded up to whole packs of `packs.pack` (10, an estimate:
|
|
380
424
|
set your own in `rules/packs.json`) with the spares said. `--json` gives each line as `{ fastener, qty, kind,
|
|
@@ -444,8 +488,8 @@ then y, then z, as `rotate` does.
|
|
|
444
488
|
(`planetary.phase`: planets go every 360° / n, and (S + R) / n is whole). `planetary()` in `@rulecad/gears` finds
|
|
445
489
|
teeth for a ratio.
|
|
446
490
|
- **What holds each part:** in an assembly that moves, every part but the first turns or slides on a joint, or is
|
|
447
|
-
fastened to the first
|
|
448
|
-
note): `{ "a": "ring", "b": "case", "fastens": true, "note": "Two push pins" }`. A part only placed somewhere is
|
|
491
|
+
fastened to the first: by a `fasten` where screws do it, or by a fit with `"fastens": true` where pins, a press or a
|
|
492
|
+
clip do (named in the fit's note): `{ "a": "ring", "b": "case", "fastens": true, "note": "Two push pins" }`. A part only placed somewhere is
|
|
449
493
|
said (`assembly.loose`): a ring gear resting on its case would turn with its planets.
|
|
450
494
|
- **Onto a shaft:** `{ "a": "arm", "b": "crank", "engage": "arm.thick" }` checks that a part slid onto a shaft, a pin or a
|
|
451
495
|
peg goes that far onto it along the joint between them (`fit.engage`), not just against its end: an arm resting on
|
|
@@ -475,21 +519,71 @@ An item can be a motor instead of a printed object: `{ "id": "drive", "motor": {
|
|
|
475
519
|
- A compound planetary is a `planetary` with `"output": { "ring", "planet", "teeth" }`: a second ring on the planets' second step, following them in phase.
|
|
476
520
|
- `motor.torque`: what reaches the joint through the gears, against the load: a fail under 1 times, a warning under the margin. It says what its figures rest on. `motor.speed`: how fast it moves and how long its range takes. Stages pass on `stageEfficiency` of the power (0.95 a mesh, an estimate).
|
|
477
521
|
- `motor.holds`: with the power on (holding torque, or stall torque) and off (detent torque, a built-in gearbox's friction, a worm that locks, gears under 50% efficient, or `"brake": "a ratchet and pawl"` on the joint). Dropping with the power off is a warning: it may be what you want.
|
|
478
|
-
- `motor.mount`: the part a motor is fastened to (a `
|
|
522
|
+
- `motor.mount`: the part a motor is fastened to (a `fasten` into the motor, or a fit that `fastens`), read as drawn: how thick it is at the screw holes against the screws' size, the screws' engagement in the motor's tapped holes (the screws as bought: their length past the plate, held to the motor's `mount_hole_depth`, at least one diameter, `engagement.steel`, or it fails; a motor item's `"screw"` may name a whole screw, `"M3x8 cap"`, to check that one), and the screws' bearing on the plastic under the motor's full torque. Its screws are counted in `cad list` and `cad order` (at the length sold that stays in the motor's thread, with the key that turns them). Then the whole part bent, by FE on the part as drawn (cubes, two across the plate at the screws): the motor's weight at its centre, along `gravity` in the pose it's checked in, and its full torque (the larger of its working and holding torque), both carried into the plate where the screws clamp it. The part is held at the joint that carries it, if one does; else where it meets the printed parts it's fastened to that sit below it; failing both, on its lowest face. It reports how far the shaft's tip moves (against the driven joint's seat, where that is on the same part, since the two move together), against the printer's `fit` clearance (or the motor's `"deflection"` in mm), and the peak stress against the material's `strength`; under 2 times either fails, and says what fixes it: the plate thickness that would do (bending goes with its cube), ribs, or how much stiffer a material would have to be. Cells this coarse read a plate 10 to 20% stiff, and a cell's stress is read at its centre, so the peak is scaled up to the surface; it's an estimate, said as one. Kept in `.cache/mount`.
|
|
479
523
|
- `motor.heat`: the motor's case against the softening point of the material the project prints in. Too hot says the current to set the driver to.
|
|
480
524
|
- A `"shaft": true` fit (or `"press"`) between a motor and what it drives reads the bore from the part as drawn: that it's on the shaft (`shaft.seat`), that its flat is there (`shaft.flat`; the shaft turns to meet it, so where the flat faces doesn't matter), how much of the flat it grips (`shaft.grip`), and, pressed on, the hoop stress in the hub (`shaft.hoop`).
|
|
481
525
|
- `cad preview --check` of an assembly with a motor writes `<assembly>-check.png`: the same six views, with a label at each joint the motor's torque passes through (what reaches it, and at the loaded joint the margin and whether it holds unpowered). The rest view never carries them.
|
|
482
526
|
- `cad preview` of an assembly with a motor draws each one at work beside the picture, as SVG: `<assembly>-<motor>-curve.svg`, its torque against speed at the output with the load and the working speed marked, and `<assembly>-<motor>-train.svg`, the torque from its shaft through each stage to the joint with the load, against what the load needs there, and whether it holds with the power on and off. The numbers are the check's.
|
|
483
527
|
|
|
528
|
+
### Beams
|
|
529
|
+
|
|
530
|
+
An item can be a beam, a length of an aluminium extrusion, a tube or a bar from `@rulecad/frames`:
|
|
531
|
+
|
|
532
|
+
```json
|
|
533
|
+
{ "id": "x1", "beam": { "profile": "2020-misumi-hfs5", "length": 300 }, "from": [0, 0, 0], "to": [300, 0, 0], "roll": 0 }
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
- `"profile"` names the profile (`2020-misumi-hfs5`, `profile-4040-item-8`, or a set in this workspace's `rules/`).
|
|
537
|
+
`"length"` is mm from end `a` to end `b`, a number or an expression (`"x1.length"`). Placed by its ends, the length
|
|
538
|
+
may be left out: it is the distance from `from` to `to`, and a length that disagrees with them is refused with both.
|
|
539
|
+
`"material"` names a material set in place of the profile's alloy. `"printed": true` is for printed beams, a later
|
|
540
|
+
release: it is refused by name for now.
|
|
541
|
+
- Placed by its ends, end `a` is at `from` and end `b` at `to`; at roll 0 its top faces up (+z), or +y when it stands
|
|
542
|
+
upright, and `"roll"` turns it about its own axis, in degrees. Or place it with `at` and `rotate` as any item, in its
|
|
543
|
+
own frame: end `a` at the origin, the beam up +z, its top +y. The face names and a picture are in the
|
|
544
|
+
`@rulecad/frames` README ("Face names in an assembly").
|
|
545
|
+
- A beam is bought: drawn faint, never on a plate, on `cad list` by profile and length (`2 × profile-2020-misumi-hfs5
|
|
546
|
+
x 300 mm a beam 150 g each`, weighed by the maker's mass per metre where the sheet gives one), and in the overlap
|
|
547
|
+
check by its envelope, a plain box. `cad check` says each beam's mass beside the sheet's, and warns of a length
|
|
548
|
+
longer than the profile is sold in. Its numbers are values: `x1.length`, `x1.width`, `x1.height`, `x1.mass`.
|
|
549
|
+
- `"ops"` lists the operations on it, each placed by an address on the beam and dimensioned from end `a`: `cut`,
|
|
550
|
+
`mitre`, `tap`, `access`, `drill`, `counterbore`, `pocket`, `notch` and `deburr`. `{ "op": "tap", "at": "a", "thread":
|
|
551
|
+
"M5" }` taps end a's bore; `{ "op": "access", "at": "top@-10", "thread": "M5" }` drills a hole for an M5 screw's key 10
|
|
552
|
+
mm from end b; `{ "op": "mitre", "at": "b", "angle": 45, "about": "top" }` mitres end b, the length then measured on
|
|
553
|
+
the long side. Numbers may be expressions. Each is cut into the beam's solid (a mitre into its envelope too), and
|
|
554
|
+
`cad check` reports its findings as `beam.op` (a hole into a slot's lips or across a tapped thread, a tap deeper than
|
|
555
|
+
the bore, a hole too near an end) and thread engagement in the alloy. What each takes is in the `@rulecad/frames`
|
|
556
|
+
README ("Operations").
|
|
557
|
+
- `cad add beam <project>/<assembly> --id x1 --profile 2020-misumi-hfs5 --from 0,0,0 --to 300,0,0 [--roll 90]` adds one.
|
|
558
|
+
|
|
559
|
+
Every beam has addresses, taken wherever an anchor is: an item's `at`, a joint's `parent` or `child`, a `loop`, a
|
|
560
|
+
fit's `a` or `b`, a fit's `access`, and a load's `at`.
|
|
561
|
+
|
|
562
|
+
| Address | Where |
|
|
563
|
+
|---|---|
|
|
564
|
+
| `x1.a`, `x1.b` | The middle of each end, its z out of the end |
|
|
565
|
+
| `x1.a.1`, `x1.b.2` | A bore in an end |
|
|
566
|
+
| `x1.top`, `x1.top.2` | A face's first and second place (a slot, or the face where it is closed), at the middle of the beam |
|
|
567
|
+
| `x1.top@120`, `x1.top@-20`, `x1.top@50%` | 120 mm from end `a`, 20 mm from end `b`, half way along |
|
|
568
|
+
| `x1.top.2@120` | The second slot of a face that has more than one |
|
|
569
|
+
|
|
570
|
+
A face's anchor has its z out of the face and its x along the beam toward `b`. An item placed at an address
|
|
571
|
+
(`{ "id": "plate", "object": "plate", "at": "x1.top@50%" }`) puts its own origin there, its z out of the face and its
|
|
572
|
+
x along the beam, turned by its `rotate` in that frame; it moves with the beam. A distance past either end is refused
|
|
573
|
+
with the beam's length: `"top@320" is past the end of profile-2020-misumi-hfs5 x 300: it is 300 mm long`. In a fit, an
|
|
574
|
+
address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm by default).
|
|
575
|
+
|
|
484
576
|
### Building it
|
|
485
577
|
|
|
486
578
|
Once an assembly is checked, these say how to make it. They all read the assembly itself, so they can't disagree with it.
|
|
487
579
|
|
|
488
|
-
- `cad order <project>/<assembly>`: the order it goes together in, each step with the part and
|
|
580
|
+
- `cad order <project>/<assembly>`: the order it goes together in, each step with the part and what fastens it. 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. What is not a screw (pins, a clip) is named on a fit that fastens: `"fastener": "push pin", "count": 2` puts it 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.
|
|
489
581
|
- `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.
|
|
490
582
|
- `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`).
|
|
583
|
+
- `cad list <project>/<assembly>` lists the beams' **cut list** after the bought parts: each mark (beams that are the same, one profile, length and set of operations, share a mark, A, B, C), its count, grams each and work, then each profile's lengths to cut, the bars to buy in the lengths it is sold in, and the cuts on each bar in order with its offcut. Every cut takes the saw's 3 mm kerf and each bar's first end is trimmed 10 mm (`CUT_DEFAULTS` in `@rulecad/frames`, each with its source); the packing is first-fit decreasing. `cad check` adds the cut list's findings (`frame.cut`): a beam longer than any length sold fails, two lengths nearer than the cut tolerance can hold apart warn, and beams of one mark are reminded to be cut against one stop. Each beam's mark is in its label in the preview and the link (`x1: mark A, profile-2020-misumi-hfs5 x 300 mm`).
|
|
584
|
+
- `cad beams <project>/<assembly>`: a cut-and-drill sheet for each mark, written to `exports/<project>/<assembly>.beam-<mark>.svg`, in mm so it prints to scale at 100%: the section at end a with each face named and the taps marked, a view of each face with work on it (that face up, end a on the left), every operation dimensioned from end a to 0.1 mm, and the operations in order, each tap with its thread and depth. The build page lists the sheets with the cut list.
|
|
491
585
|
- `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.
|
|
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.
|
|
586
|
+
- `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 beams' cut list and their sheets, 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.
|
|
493
587
|
- 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.
|
|
494
588
|
|
|
495
589
|
## Optimised parts
|
package/TUTORIAL.md
CHANGED
|
@@ -73,7 +73,7 @@ npx cad new home/hook
|
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
That makes `projects/home/objects/hook.json` and `hook.js` from a template. Replace the `.json` with the hook's
|
|
76
|
-
variables. The screw's
|
|
76
|
+
variables. The screw's hole comes from the shape below, which asks `v.fixings` for it by the screw's thread:
|
|
77
77
|
|
|
78
78
|
```json projects/home/objects/hook.json
|
|
79
79
|
{
|
|
@@ -81,33 +81,37 @@ variables. The screw's sizes come from the `m4` rule set, which is copied into `
|
|
|
81
81
|
"name": "hook",
|
|
82
82
|
"title": "Wall hook",
|
|
83
83
|
"version": "0.1.0",
|
|
84
|
-
"uses": ["x1c"
|
|
84
|
+
"uses": ["x1c"],
|
|
85
85
|
"material": "PETG",
|
|
86
86
|
"orientation": "On its side, so the layers run along the arm and it can't snap off across them.",
|
|
87
87
|
"variables": {
|
|
88
88
|
"width": { "value": 20, "unit": "mm", "rule": "Wide enough for a coat's loop", "label": "Width", "show": true, "tweak": { "min": 10, "max": 60 } },
|
|
89
89
|
"plate": { "value": 50, "unit": "mm", "rule": "The back plate: room for a screw above the arm", "label": "Plate", "show": true },
|
|
90
90
|
"reach": { "value": 30, "unit": "mm", "rule": "How far the arm stands out from the wall", "label": "Reach", "show": true, "tweak": { "min": 15, "max": 60 } },
|
|
91
|
-
"thick": { "value": "x1c.line * 10", "unit": "mm", "rule": "Ten print lines: stiff enough for a coat" }
|
|
92
|
-
"hole": { "value": "m4.clearance + x1c.hole_comp", "unit": "mm", "rule": "An M4 screw's clearance hole, widened for how holes print", "interface": true }
|
|
91
|
+
"thick": { "value": "x1c.line * 10", "unit": "mm", "rule": "Ten print lines: stiff enough for a coat" }
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
```
|
|
96
95
|
|
|
97
96
|
Then the shape. `main(v)` gets the variables as `v`, with the rule sets (`v.x1c.line`), print-aware shapes
|
|
98
|
-
(`v.shapes`) and booleans (`v.ops`). Z is up and the bed is z = 0: draw the
|
|
97
|
+
(`v.shapes`), screws, nuts and inserts (`v.fixings`) and booleans (`v.ops`). Z is up and the bed is z = 0: draw the
|
|
98
|
+
part the way it will print.
|
|
99
|
+
|
|
100
|
+
`v.fixings.hole('M4', ...)` is a clearance hole for an M4 screw, sized from the `m4` rule set: 4.5 mm, the normal
|
|
101
|
+
clearance ISO 273 gives, plus the printer's `x1c.hole_comp` (0.1 mm), since a printed hole comes out small. Lying on
|
|
102
|
+
its side, it is drawn as a teardrop, so its roof needs no support. The check says what it was drawn to.
|
|
99
103
|
|
|
100
104
|
```js projects/home/objects/hook.js
|
|
101
|
-
// A wall hook: a back plate with a screw
|
|
105
|
+
// A wall hook: a back plate with a hole for an M4 screw, and an arm. It lies on its side to print (z is its width).
|
|
102
106
|
import jscad from '@jscad/modeling'
|
|
103
107
|
const { cuboid } = jscad.primitives
|
|
104
108
|
|
|
105
109
|
export function main (v) {
|
|
106
110
|
const plate = cuboid({ size: [v.plate, v.thick, v.width], center: [0, v.thick / 2, v.width / 2] })
|
|
107
111
|
const arm = cuboid({ size: [v.thick, v.reach, v.width], center: [(v.thick - v.plate) / 2, v.thick + v.reach / 2, v.width / 2] })
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
const screw = v.
|
|
112
|
+
// the screw's hole across the part as it prints, from the plate's face out through its back: v.fixings sizes it
|
|
113
|
+
// from the thread's rule set and draws it as a teardrop, so its roof needs no support
|
|
114
|
+
const screw = v.fixings.hole('M4', { depth: v.thick, at: [v.plate / 2 / 2, v.thick, v.width / 2], into: '-y' })
|
|
111
115
|
return v.ops.subtract(v.ops.union(plate, arm), screw)
|
|
112
116
|
}
|
|
113
117
|
```
|
|
@@ -129,7 +133,8 @@ The check names mistakes rather than drawing something else. The ones everyone m
|
|
|
129
133
|
|---|---|
|
|
130
134
|
| a number in the `.js`: `v.plate / 4` | `numbers in hook.js that should be variables: line 10: 4` |
|
|
131
135
|
| a variable that isn't there: `v.thik` | `v.thik: the design has no variable "thik" (did you mean "thick"?)` |
|
|
132
|
-
| a rule that isn't there: `
|
|
136
|
+
| a rule that isn't there: `x1c.lien` | `"x1c.lien": no rule "lien" in x1c (hook.json: variables.thick.value)` |
|
|
137
|
+
| a thread that isn't there: `v.fixings.hole('M44', ...)` | `fixingModel: no thread "M44" (did you mean M4?)`, with the threads there are |
|
|
133
138
|
| a misspelt key in the `.json`: `"lable"` | `variables.thick.lable: not allowed here (did you mean "label"?)` |
|
|
134
139
|
| nothing returned from `main` | `main() returned no shape: return a JSCAD solid, or named parts` |
|
|
135
140
|
|
|
@@ -153,7 +158,6 @@ npx cad new home/screw
|
|
|
153
158
|
"version": "0.1.0",
|
|
154
159
|
"role": "reference",
|
|
155
160
|
"variables": {
|
|
156
|
-
"d": { "value": 4, "unit": "mm", "rule": "An M4 screw's thread", "interface": true },
|
|
157
161
|
"length": { "value": 16, "unit": "mm", "rule": "Long enough to go through the plate into a wall plug" },
|
|
158
162
|
"sides": { "value": 32, "rule": "Sides drawn round the shank" }
|
|
159
163
|
}
|
|
@@ -161,11 +165,13 @@ npx cad new home/screw
|
|
|
161
165
|
```
|
|
162
166
|
|
|
163
167
|
```js projects/home/objects/screw.js
|
|
164
|
-
// An M4 screw's shank, lying along y: something the hook fits, not something to print.
|
|
168
|
+
// An M4 screw's shank, lying along y: something the hook fits, not something to print. Its diameter is the thread's
|
|
169
|
+
// own, from the same rule set as the hook's hole.
|
|
165
170
|
import jscad from '@jscad/modeling'
|
|
166
171
|
|
|
167
172
|
export function main (v) {
|
|
168
|
-
|
|
173
|
+
const thread = v.fixings.fixingModel('M4')
|
|
174
|
+
return jscad.transforms.rotateX(Math.PI / 2, jscad.primitives.cylinder({ radius: thread.major / 2, height: v.length, segments: v.sides }))
|
|
169
175
|
}
|
|
170
176
|
```
|
|
171
177
|
|
|
@@ -199,8 +205,12 @@ Hook on its screw (fit: hook 0.1.0, screw 0.1.0)
|
|
|
199
205
|
✓ The screw in its hole: closest gap 0.295 mm
|
|
200
206
|
```
|
|
201
207
|
|
|
202
|
-
|
|
203
|
-
shape from them, and a check against the thing it meets.
|
|
208
|
+
Ask `v.fixings` for an M3 hole in the hook and the check fails with the number: the M4 screw overlaps it. That is
|
|
209
|
+
the loop: rules, a shape from them, and a check against the thing it meets.
|
|
210
|
+
|
|
211
|
+
A screw that holds printed parts to each other gets more than a fit: a `fasten` says which parts it passes through
|
|
212
|
+
and what it ends in, and the check chooses its length, finds its holes, and puts it on the shopping list. The worked
|
|
213
|
+
examples screw a board into its case with one (chapter 6) and explain it in full in chapter 15.
|
|
204
214
|
|
|
205
215
|
## 7. Share it
|
|
206
216
|
|
package/bin/cad.mjs
CHANGED
|
@@ -20,11 +20,11 @@ import { schemaFindings } from '../lib/schema.mjs';
|
|
|
20
20
|
import { readJson } from '../lib/host.mjs';
|
|
21
21
|
import { optimised, readProblem, analysePart, picture, problemFile } from '../lib/optimise.mjs';
|
|
22
22
|
import { evaluate } from '../lib/rules.mjs';
|
|
23
|
-
import { setVariables, addToAssembly, parseValue } from '../lib/edit.mjs';
|
|
23
|
+
import { setVariables, addToAssembly, fastenFromFitsEdit, parseValue } from '../lib/edit.mjs';
|
|
24
24
|
import { setAt } from '../lib/jsonedit.mjs';
|
|
25
25
|
import { threemf, slotOf } from '../lib/threemf.mjs';
|
|
26
26
|
import { liveView } from '../lib/live.mjs';
|
|
27
|
-
import { checkSets, drawSet, draftSet } from '../lib/sheet.mjs';
|
|
27
|
+
import { checkSets, drawSet, draftSet, draftPart, draftParts } from '../lib/sheet.mjs';
|
|
28
28
|
import { filaments, slots, linkTo, objectModel, assemblyModel, VIEW } from '../lib/links.mjs';
|
|
29
29
|
|
|
30
30
|
// What the print file asks of the AMS: which filament each kind of part prints in
|
|
@@ -47,15 +47,19 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
47
47
|
cad agents AGENTS.md: how an AI agent should design in this workspace
|
|
48
48
|
cad trust allow what this workspace's cad.config.json asks (no sandbox, its own targets)
|
|
49
49
|
cad rules <project>/<object> every variable: value, the rule behind it, its source
|
|
50
|
-
cad rules check [set …] rule sets held to what makes them traceable (exit 1 on a failure) [--json]
|
|
50
|
+
cad rules check [set …] rule sets held to what makes them traceable (exit 1 on a failure) [--json]; notes,
|
|
51
|
+
never failures: an alias in "interface", and what the kit's set has that your copy lacks
|
|
51
52
|
cad rules draw <set> a dimension drawing of what a set says a part mounts by, <set>.svg, to compare with its datasheet [--out file]
|
|
52
53
|
cad rules draft <name> --from <file.pdf> the figures in a datasheet's text, into rules/<name>.json for you to name and check (all kind estimate)
|
|
54
|
+
cad rules draft profile|slot|slot_nut <name> every field a beam's profile, a slot family or a slot nut has, to fill from its sheet
|
|
53
55
|
cad values <project>/<object> [names…] the object's variables, resolved [--json]
|
|
54
56
|
cad set <project>/<object> name=value … change variables, keeping the file's layout [--unit, --rule, --label, --new to add one]
|
|
55
|
-
cad add fit|joint|item|loop|pose <project>/<assembly> --a … --b … --min … add to an assembly, keeping its layout
|
|
57
|
+
cad add fit|joint|item|beam|loop|pose <project>/<assembly> --a … --b … --min … add to an assembly, keeping its layout
|
|
56
58
|
cad add fasten <project>/<assembly> --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2
|
|
57
59
|
a screwed joint (or --holes bracket.body for the part's own holes) [--nut [hex|square|lock]]
|
|
58
60
|
[--washer] [--length 12] [--torque 0.5] [--note …]
|
|
61
|
+
cad add fasten <project>/<assembly> --from-fits a fasten in place of a holes fit and a fit that fastens the same parts
|
|
62
|
+
(the screw read from them, or --screw "M2 cap")
|
|
59
63
|
cad why <project>/<object>.<name> what a value reads, down to the rules and their sources [--json] [--depth N]
|
|
60
64
|
cad check <project>/<object> raw numbers in the design, then printability (exit 1 on a failure) [--json: findings as data]
|
|
61
65
|
cad preview <project>/<object> six views as a PNG in .preview/ (prints the path); an assembly with a motor also gets
|
|
@@ -91,7 +95,8 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
91
95
|
.preview/, and any stroke refused [--calibrate: the calibration drawing] [--tol 0.1] [--json]
|
|
92
96
|
cad order <project>/<assembly> the order it goes together in, each step with its fasteners [--preview: an exploded picture of each step in .preview/]
|
|
93
97
|
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]
|
|
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
|
|
98
|
+
cad list <project>/<assembly> what it takes to build: bought parts by set, the beams' cut list and bars to buy, every screw, nut and insert in packs, wire, printed parts in grams
|
|
99
|
+
cad beams <project>/<assembly> a cut-and-drill sheet for each mark of beam (beams that are the same share one), to scale, written to exports/ [--json]
|
|
95
100
|
cad wires <project>/<assembly> the wiring sheet: each wire's length, gauge and ends, written to exports/ [--out wiring.md]
|
|
96
101
|
cad measured <project>/<assembly> <name>=<value> … a measurement, where the estimate was: a rule (x1c.press=0.08) or a
|
|
97
102
|
check's prediction (task.accuracy=0.8): says what moved, and keeps a ledger of predicted
|
|
@@ -99,10 +104,17 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
99
104
|
[--table: what the assembly still assumes, as Markdown; --out MEASURE.md: kept in that file]
|
|
100
105
|
The fixings coupon's rules need no --rule: x1c.pilot_m4, x1c.insert_m3 (and _petg for one
|
|
101
106
|
plastic), x1c.nut_fit, x1c.nut_slip, x1c.thread_gap, x1c.thread_flank (45 or 60)
|
|
107
|
+
The slot coupon's need no --rule: x1c.slot_fit, x1c.printed_slot_fit; a slot measured by
|
|
108
|
+
caliper goes in your copy of its set (slot-8.opening=8.1), checked as a slot
|
|
102
109
|
cad measure <model.stl|3mf> a model from elsewhere, measured: size, the stretches along its length with the same
|
|
103
110
|
cross-section, and each section's shape, with a drawing in .preview/measure/
|
|
104
111
|
[--along x|y|z] [--at 10,50: sections there too] [--line 0.6,2.5;4.6,2.5: where lines
|
|
105
112
|
along it are inside] [--rules <name> --source <url> --licence "…": draft rules]
|
|
113
|
+
cad measure <beam.stl|3mf|section.dxf> --profile <name> a beam's profile from a model of it, or a DXF of its
|
|
114
|
+
section: its outline to rules/outlines/<name>.json, its slots (opening, lip, width,
|
|
115
|
+
depth) and bores as a draft profile set, each slot matched to a known slot family or
|
|
116
|
+
drafted as a new one, and a drawing of what was found [--source <url> --licence "…"]
|
|
117
|
+
[--tol 0.1: how close a slot must be to a family, mm] [--along x|y|z] [--force]
|
|
106
118
|
cad match <project>/<object> <model.stl|3mf> how closely the design matches a model: both ways, signed, with the
|
|
107
119
|
worst places and sections through them [--tol 0.2 (default: the printer's fit)]
|
|
108
120
|
[--place "rz90 t1,2,3": how to lay the model over the design, else it is fitted]
|
|
@@ -123,22 +135,22 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
123
135
|
|
|
124
136
|
// Every command and option there is: a misspelt one is refused by name, not passed over
|
|
125
137
|
const COMMANDS = ['new', 'import-kle', 'clone', 'agents', 'trust', 'rules', 'values', 'set', 'add', 'why', 'check', 'preview', 'animate', 'optimise', 'optimize', 'export',
|
|
126
|
-
'show', 'link', 'status', 'release', 'history', 'diff', 'printed', 'measure', 'measured', 'list', 'wires', 'machine', 'plot', 'plates', 'order', 'match', 'variants', 'compare', 'help'];
|
|
138
|
+
'show', 'link', 'status', 'release', 'history', 'diff', 'printed', 'measure', 'measured', 'list', 'beams', 'wires', 'machine', 'plot', 'plates', 'order', 'match', 'variants', 'compare', 'help'];
|
|
127
139
|
const OPTIONS = ['table', 'calibrate', 'check', 'turns', 'preview', 'gap', 'no-steps', 'all', 'along', 'at', 'bump', 'depth', 'dry-run', 'explode', 'force', 'fresh', 'json', 'licence', 'license', 'long', 'm', 'material', 'md', 'name', 'new',
|
|
128
|
-
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
140
|
+
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'profile', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
129
141
|
'sweep', 'tol', 'trailer', 'ttl', 'version', 'watch', 'line',
|
|
130
142
|
'unit', 'rule', 'label', 'from', 'out', // cad set, cad rules
|
|
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
|
|
143
|
+
'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate', 'to', 'roll', // cad add
|
|
144
|
+
'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque', 'from-fits']; // cad add fasten
|
|
133
145
|
// What a command takes, where that isn't <project>/<object>
|
|
134
|
-
const USAGE = { add: 'fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
|
|
146
|
+
const USAGE = { add: 'fit|joint|item|beam|loop|pose|fasten <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
|
|
135
147
|
optimise: '<project>/<problem>', optimize: '<project>/<problem>', history: '<project>[/<object>]', release: '<project>[/<object>] -m "what changed"',
|
|
136
148
|
diff: '<project>/<object> <from> [<to>]', compare: '<project>/<object> <a> <b>', match: '<project>/<object> <model.stl|model.3mf>', clone: '<board.kicad_pcb | GitHub link> <name>' };
|
|
137
149
|
|
|
138
150
|
const args = process.argv.slice(2);
|
|
139
151
|
// Options that stand alone. Every other takes the value after it: --name value, or -m for one-letter names
|
|
140
152
|
// (--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'];
|
|
153
|
+
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', 'from-fits'];
|
|
142
154
|
const opt = (k) => {
|
|
143
155
|
const i = args.findIndex((a) => a === `--${k}` || (k.length === 1 && a === `-${k}`));
|
|
144
156
|
if (i < 0) return undefined;
|
|
@@ -338,24 +350,42 @@ async function analyses(b, d, tag) {
|
|
|
338
350
|
// cad rules check / draw / draft: rule sets themselves, not a design's use of them
|
|
339
351
|
function ruleSheets(what, names) {
|
|
340
352
|
if (what === 'check') {
|
|
341
|
-
|
|
342
|
-
|
|
353
|
+
// a set fails on a finding of level fail; a warning or a note is said and the set still passes
|
|
354
|
+
const results = checkSets(names), fails = (r) => r.findings.filter((x) => x.level === 'fail').length, bad = results.filter(fails), noted = results.filter((r) => r.findings.length && !fails(r));
|
|
355
|
+
if (opt('json')) console.log(JSON.stringify(results.map((r) => ({ name: r.name, findings: r.findings, ...(r.notes ? { notes: r.notes } : {}) })), null, 2));
|
|
343
356
|
else {
|
|
344
|
-
for (const r of
|
|
345
|
-
|
|
357
|
+
for (const r of results.filter((x) => x.findings.length)) { console.log(`${r.name}: ${fails(r) ? `${fails(r)} to fix` : `passes, ${r.findings.length} to know`}`); for (const x of r.findings) console.log(` ${{ fail: 'FAIL', warn: 'WARN', info: 'NOTE' }[x.level] ?? 'FAIL'} ${x.text} (${x.code})`); }
|
|
358
|
+
// notes never fail: an alias names one line per set, what a copy lacks of the kit's set says it whole
|
|
359
|
+
for (const r of results.filter((x) => x.notes)) {
|
|
360
|
+
const alias = r.notes.filter((x) => x.code === 'rules.alias'), rest = r.notes.filter((x) => x.code !== 'rules.alias');
|
|
361
|
+
if (alias.length) console.log(`${r.name}: NOTE ${alias.map((x) => `${x.rule} is also read as ${x.values.alias}`).join(', ')} (rules.alias)`);
|
|
362
|
+
for (const x of rest) console.log(`${r.name}: NOTE ${x.text} (${x.code})`);
|
|
363
|
+
}
|
|
364
|
+
console.log(`${results.length - bad.length} of ${results.length} rule sets pass${noted.length ? ` (${noted.length} with something to know)` : ''}`);
|
|
346
365
|
}
|
|
347
366
|
process.exitCode = bad.length ? 1 : 0;
|
|
348
367
|
return;
|
|
349
368
|
}
|
|
350
369
|
const name = names[0];
|
|
351
|
-
if (!name) throw new Error(`usage: cad rules ${what} <set>${what === 'draft' ?
|
|
370
|
+
if (!name) throw new Error(`usage: cad rules ${what} <set>${what === 'draft' ? ` --from <file.pdf>, or cad rules draft ${draftParts().join('|')} <name>` : ''}`);
|
|
352
371
|
if (what === 'draw') { const to = opt('out') || `${name}.svg`; fs.writeFileSync(to, drawSet(name)); return console.log(`drew ${to}: compare it with the datasheet`); }
|
|
353
|
-
|
|
372
|
+
const save = (as, set) => {
|
|
373
|
+
const to = path.join(paths.rules ? paths.rules() : path.join(WS, 'rules'), `${as}.json`);
|
|
374
|
+
if (fs.existsSync(to) && !opt('force')) throw new Error(`${path.relative(WS, to)} already exists (--force replaces it)`);
|
|
375
|
+
fs.mkdirSync(path.dirname(to), { recursive: true }); fs.writeFileSync(to, JSON.stringify(set, null, 2) + '\n');
|
|
376
|
+
return to;
|
|
377
|
+
};
|
|
378
|
+
// cad rules draft profile <name>: every field of the vocabulary for that part, to fill from a sheet
|
|
379
|
+
if (draftParts().includes(name) && !opt('from')) {
|
|
380
|
+
const part = name, as = names[1];
|
|
381
|
+
if (!as) throw new Error(`usage: cad rules draft ${part} <name>`);
|
|
382
|
+
const to = save(as, draftPart(part, as));
|
|
383
|
+
return console.log(`a draft ${part.replace('_', ' ')} in ${path.relative(WS, to)}, every figure an estimate: fill it from the maker's sheet (source, page, date), then cad rules check ${as} and cad rules draw ${as}`);
|
|
384
|
+
}
|
|
385
|
+
if (!opt('from')) throw new Error(`usage: cad rules draft <name> --from <file.pdf>, or cad rules draft ${draftParts().join('|')} <name>`);
|
|
354
386
|
const { set, found } = draftSet(name, opt('from'));
|
|
355
387
|
if (!found) return console.log(`no figures in ${opt('from')}'s text: it's probably a picture of a drawing, so read it by eye and write rules/${name}.json by hand`);
|
|
356
|
-
const to =
|
|
357
|
-
if (fs.existsSync(to) && !opt('force')) throw new Error(`${path.relative(WS, to)} already exists (--force replaces it)`);
|
|
358
|
-
fs.mkdirSync(path.dirname(to), { recursive: true }); fs.writeFileSync(to, JSON.stringify(set, null, 2) + '\n');
|
|
388
|
+
const to = save(name, set);
|
|
359
389
|
return console.log(`${found} figures in ${path.relative(WS, to)}, every one an estimate: name them from the vocabulary, check them against the datasheet, then cad rules check ${name}`);
|
|
360
390
|
}
|
|
361
391
|
|
|
@@ -422,7 +452,12 @@ async function main() {
|
|
|
422
452
|
if (cmd === 'clone') return cloneBoard(ref, pos[2], { source: opt('source'), licence: opt('licence') || opt('license'), force: !!opt('force'), noModels: !!opt('no-models') });
|
|
423
453
|
if (cmd === 'status') return status(ref);
|
|
424
454
|
if (cmd === 'measure') {
|
|
425
|
-
if (!ref) throw new Error('usage: cad measure <model.stl|model.3mf> [--along x] [--at 10,50] [--line 0.6,2.5] [--rules <name>]');
|
|
455
|
+
if (!ref) throw new Error('usage: cad measure <model.stl|model.3mf> [--along x] [--at 10,50] [--line 0.6,2.5] [--rules <name>], or cad measure <beam.stl|3mf|section.dxf> --profile <name>');
|
|
456
|
+
if (opt('profile')) {
|
|
457
|
+
const { measureProfile } = await import('../lib/profilemeasure.mjs');
|
|
458
|
+
return measureProfile(ref, { profile: opt('profile'), along: opt('along'), tol: opt('tol') && opt('tol') !== true ? opt('tol') : undefined, source: opt('source'), licence: opt('licence') || opt('license'), force: !!opt('force'), pictures: !opt('no-pictures') });
|
|
459
|
+
}
|
|
460
|
+
if (/\.dxf$/i.test(ref)) throw new Error('a DXF is a drawing of a section, not a model: cad measure <section.dxf> --profile <name> reads a beam\'s profile from it');
|
|
426
461
|
const list = (k) => (opt(k) && opt(k) !== true ? String(opt(k)).split(k === 'line' ? ';' : ',').filter(Boolean) : []);
|
|
427
462
|
return measure(ref, { along: opt('along'), at: list('at'), line: list('line'), rules: opt('rules'), source: opt('source'), licence: opt('licence') || opt('license'), force: !!opt('force'), pictures: !opt('no-pictures') });
|
|
428
463
|
}
|
|
@@ -431,7 +466,7 @@ async function main() {
|
|
|
431
466
|
if (cmd === 'variants') return variants(locate(ref));
|
|
432
467
|
if (cmd === 'compare') return compareVariants(locate(ref), pos[2], pos[3]);
|
|
433
468
|
if (cmd === 'measured') return measuredCommand(ref);
|
|
434
|
-
if (cmd === 'list' || cmd === 'wires') return listCommand(cmd, ref);
|
|
469
|
+
if (cmd === 'list' || cmd === 'wires' || cmd === 'beams') return listCommand(cmd, ref);
|
|
435
470
|
if (cmd === 'machine' || cmd === 'plot') return machineCommand(cmd, ref);
|
|
436
471
|
if (cmd === 'plates' || cmd === 'order') return platesCommand(cmd, ref);
|
|
437
472
|
if (cmd === 'history') return history(ref);
|
|
@@ -572,12 +607,24 @@ async function editAssembly(what, ref) {
|
|
|
572
607
|
const list = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => parseValue(x.trim())) : undefined);
|
|
573
608
|
const pick = (keys) => Object.fromEntries(keys.map((k) => [k, typeof opt(k) === 'string' ? parseValue(opt(k)) : undefined]).filter(([, v]) => v !== undefined));
|
|
574
609
|
const text = (keys) => Object.fromEntries(keys.filter((k) => typeof opt(k) === 'string').map((k) => [k, String(opt(k))]));
|
|
610
|
+
// (an item's at is a point, 1,2,3, or an address on a beam: --at x1.top@50%)
|
|
611
|
+
const at = () => (typeof opt('at') !== 'string' ? {} : /^[a-z][\w-]*\./i.test(opt('at')) ? { at: String(opt('at')) } : { at: list('at') });
|
|
575
612
|
let entry;
|
|
576
613
|
if (what === 'fit') entry = { ...text(['a', 'b']), ...pick(['min', 'max']), ...(list('poses') ? { poses: list('poses').map(String) } : {}), ...text(['note', 'label']) };
|
|
577
614
|
else if (what === 'joint') entry = { ...text(['id', 'type', 'parent', 'child', 'label', 'follow']), ...pick(['min', 'max', 'value', 'ratio']) };
|
|
578
|
-
else if (what === '
|
|
615
|
+
else if (what === 'beam') {
|
|
616
|
+
if (typeof opt('profile') !== 'string') throw new Error('usage: cad add beam <project>/<assembly> --id x1 --profile 2020-misumi-hfs5 --from 0,0,0 --to 300,0,0 [--roll 90] [--length 300] [--material al6063-t5], or --length 300 --at 0,0,0 --rotate 0,90,0');
|
|
617
|
+
entry = { ...text(['id']), beam: { profile: String(opt('profile')), ...pick(['length']), ...text(['material']) }, ...(list('from') ? { from: list('from') } : {}), ...(list('to') ? { to: list('to') } : {}), ...pick(['roll']), ...at(), ...(list('rotate') ? { rotate: list('rotate') } : {}) };
|
|
618
|
+
} else if (what === 'item') entry = { ...text(['id', 'object', 'assembly', 'variant']), ...at(), ...(list('rotate') ? { rotate: list('rotate') } : {}),
|
|
579
619
|
...(typeof opt('set') === 'string' ? { set: Object.fromEntries(sets() && Object.entries(sets()).map(([k, v]) => [k, parseValue(v)])) } : {}) };
|
|
580
620
|
else if (what === 'loop') entry = text(['a', 'b', 'label']);
|
|
621
|
+
else if (what === 'fasten' && opt('from-fits')) { // a holes fit and a fit that fastens, put as one fasten
|
|
622
|
+
const s = await buildAssembly(ref), { fastenFromFits } = await import('../lib/fasten.mjs');
|
|
623
|
+
const r = fastenFromFitsEdit(ref, fastenFromFits(s), { screw: typeof opt('screw') === 'string' ? opt('screw') : undefined });
|
|
624
|
+
if (opt('json')) return console.log(JSON.stringify(r));
|
|
625
|
+
for (const x of r.added) console.log(`added a fasten to ${path.relative(WS, r.file)} in place of its holes fit and its fit that fastens: ${JSON.stringify(x)}`);
|
|
626
|
+
return console.log(`check its screws: cad check ${ref}`);
|
|
627
|
+
}
|
|
581
628
|
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
629
|
const names = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => x.trim()).filter(Boolean) : undefined);
|
|
583
630
|
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']) };
|
|
@@ -586,8 +633,8 @@ async function editAssembly(what, ref) {
|
|
|
586
633
|
const pairs = positional().slice(3);
|
|
587
634
|
if (typeof opt('name') !== 'string' || !pairs.length) throw new Error('usage: cad add pose <project>/<assembly> --name open hinge=90 [joint=value …]');
|
|
588
635
|
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)]; })) };
|
|
589
|
-
} else throw new Error('usage: cad add fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …');
|
|
590
|
-
const r = addToAssembly(ref, what, entry);
|
|
636
|
+
} else throw new Error('usage: cad add fit|joint|item|beam|loop|pose|fasten <project>/<assembly> --key value …');
|
|
637
|
+
const r = addToAssembly(ref, what === 'beam' ? 'item' : what, entry);
|
|
591
638
|
if (opt('json')) return console.log(JSON.stringify({ ...r, added: entry }));
|
|
592
639
|
console.log(`added ${/^[aeiou]/.test(what) ? "an" : "a"} ${what} to ${path.relative(WS, r.file)}`);
|
|
593
640
|
}
|
|
@@ -1003,6 +1050,13 @@ async function listCommand(what, ref) {
|
|
|
1003
1050
|
const { shoppingList, listText } = await import('../lib/list.mjs'), l = shoppingList(s);
|
|
1004
1051
|
return console.log(opt('json') ? JSON.stringify(l, null, 2) : listText(ref, l));
|
|
1005
1052
|
}
|
|
1053
|
+
if (what === 'beams') {
|
|
1054
|
+
const { writeBeamSheets } = await import('../lib/beams.mjs'), sheets = writeBeamSheets(s);
|
|
1055
|
+
if (opt('json')) return console.log(JSON.stringify(sheets.map((x) => ({ ...x, file: path.relative(WS, x.file) })), null, 2));
|
|
1056
|
+
if (!sheets.length) return console.log(`${ref} has no beams`);
|
|
1057
|
+
for (const x of sheets) say(` mark ${x.mark} (${x.items.join(', ')}), 1:${x.scale}: ${path.relative(WS, x.file)}`);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1006
1060
|
const { wiresFor } = await import('../lib/assembly.mjs'), { wiringSheet } = await import('../lib/wires.mjs'), rows = wiresFor(s);
|
|
1007
1061
|
if (opt('json')) return console.log(JSON.stringify(rows.map(({ route, ...r }) => r), null, 2));
|
|
1008
1062
|
if (!rows.length) return console.log(`${ref} has no "wires"`);
|