@rulecad/cad 0.7.48 → 0.7.55
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 +24 -6
- package/EXAMPLES.md +347 -1
- package/README.md +136 -3
- package/bin/cad.mjs +73 -24
- package/lib/assembly.mjs +96 -34
- package/lib/beams.mjs +147 -0
- package/lib/bought.mjs +1 -1
- package/lib/buildpage.mjs +6 -3
- package/lib/design.mjs +48 -13
- package/lib/edit.mjs +12 -4
- package/lib/fasten.mjs +824 -0
- package/lib/fixings.mjs +42 -0
- package/lib/frames.mjs +63 -0
- package/lib/links.mjs +2 -1
- package/lib/list.mjs +38 -12
- package/lib/measured.mjs +69 -8
- package/lib/motors.mjs +48 -7
- package/lib/order.mjs +20 -6
- package/lib/preview/page.html +4 -2
- package/lib/preview.mjs +3 -2
- package/lib/profilemeasure.mjs +278 -0
- package/lib/sandbox-hooks.mjs +2 -2
- package/lib/sandbox-run.mjs +6 -3
- package/lib/sandbox.mjs +9 -6
- package/lib/schema.mjs +1 -1
- package/lib/sheet.mjs +143 -4
- package/package.json +5 -3
- package/schemas/assembly.schema.json +41 -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
|
|
|
@@ -157,6 +158,17 @@ own copy anywhere and name it in `viewUrl`.
|
|
|
157
158
|
strain at a travel, and `printable(shape, printer, material, model)` for how it prints. Drawn flat: bending along y,
|
|
158
159
|
width up z, so a flexure bends within its layers.
|
|
159
160
|
- `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).
|
|
161
|
+
- `v.fixings`: screws, nuts and inserts (`@rulecad/fixings`), bound to the project: `hole('M3', { kind: 'pilot', at })`
|
|
162
|
+
for a hole sized by what it is for, `counterbore`, `countersink`, `nutPocket`, `nutTrap`, `squareNutSlot` and
|
|
163
|
+
`insertBoss` for seats, `screw`, `nut`, `washer` and `insert` as light reference solids, `thread` for one cut to
|
|
164
|
+
print, and `engagement`, `seating` and `lengthFor` for first sums. Each reads the workspace's own thread set
|
|
165
|
+
(`rules/m3.json`) before the kit's, the project's printer and (for what a thread is in) its material, so a design
|
|
166
|
+
types no diameter and passes none. `cad check` lists what each call drew and the rule it rests on (`hole.drawn`,
|
|
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).
|
|
160
172
|
- `v.gears`: gears (`@rulecad/gears`): `spur`, `rack` and `internal` as shapes, from a module and teeth, each with its
|
|
161
173
|
model (`gearModel`, `rackModel`, `internalModel`) and `printable(model, printer, width)`. Drawn flat: the axis up z,
|
|
162
174
|
the first tooth on +x, the face on the bed. Two gears in an assembly mesh with a joint's `mesh` (see Joints).
|
|
@@ -246,6 +258,26 @@ faces) show up as an even offset: set `--tol` above them.
|
|
|
246
258
|
A model's licence limits what you make from it, not what you learn: measurements are facts, but a non-commercial or
|
|
247
259
|
share-alike model's shape shouldn't be copied into a design under another licence. `measure` warns about those.
|
|
248
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
|
+
|
|
249
281
|
## Assemblies
|
|
250
282
|
|
|
251
283
|
`projects/<project>/assemblies/<name>.json` places objects together. Positions are expressions over rules and the
|
|
@@ -274,7 +306,7 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
|
|
|
274
306
|
can't write or delete files, start programs or workers, or load addons, and it reads only the workspace and the
|
|
275
307
|
packages designs use, by their real paths (a `node_modules` link spelled through another link, as macOS spells its
|
|
276
308
|
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
|
|
309
|
+
`@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
310
|
started with none of your environment (no tokens). Those shut the ordinary roads to the network, not every one:
|
|
279
311
|
before Node 25 the permission model doesn't cover the network, so a design written to get round them might still
|
|
280
312
|
reach it. Run only designs you trust. It gets its values as data and returns its parts; what it prints
|
|
@@ -323,6 +355,57 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
|
|
|
323
355
|
- `check`, `preview` (`--explode` lifts each kind of object above the last: plate, switches, keycaps), `show`, `link` and, for plates, `export` all take
|
|
324
356
|
`<project>/<assembly>`.
|
|
325
357
|
|
|
358
|
+
### Screwed joints: `fasten`
|
|
359
|
+
|
|
360
|
+
A joint held by screws is one relation, and it knows the screw:
|
|
361
|
+
|
|
362
|
+
```json
|
|
363
|
+
"fasten": [
|
|
364
|
+
{ "screw": "M3 cap", "through": ["bracket"], "into": "base", "at": ["bracket.h1", "bracket.h2"] },
|
|
365
|
+
{ "screw": "M3x16 cap", "through": ["cover", "frame"], "into": "frame-back", "holes": "cover.body", "nut": true, "washer": true }
|
|
366
|
+
]
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
`screw` names the thread and head as `@rulecad/fixings` reads them (`M3 cap`, `M4 button`, `M3x12 countersunk`,
|
|
370
|
+
`6-32 UNC cap`). `through` lists the parts the screw passes, in order from under its head, and `into` is the part it
|
|
371
|
+
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
|
|
372
|
+
centre line, the anchor's axis along the screw), or `holes`, a part whose own round holes are the places (for a
|
|
373
|
+
circuit board, its mounting holes). `nut` (`true`, `hex`, `square` or `lock`) says a nut holds the screw where the
|
|
374
|
+
last part does not; `washer` puts a plain washer under the head; `length` gives the length where the name has none;
|
|
375
|
+
`torque` gives the tightening torque in N m. Add one with `cad add fasten <project>/<assembly> --screw "M3 cap"
|
|
376
|
+
--through bracket --into base --at bracket.h1,bracket.h2`.
|
|
377
|
+
|
|
378
|
+
Nothing about the holes is declared. Each part is read as drawn: along the screw's axis the mesh is sliced, and the
|
|
379
|
+
outline round the axis gives the hole's centre, its diameter (across its corners, as it was drawn) and where it
|
|
380
|
+
starts and stops. From that the check says:
|
|
381
|
+
|
|
382
|
+
| Finding | What it checks |
|
|
383
|
+
|---|---|
|
|
384
|
+
| `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 |
|
|
385
|
+
| `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 |
|
|
386
|
+
| `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 |
|
|
387
|
+
| `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 |
|
|
388
|
+
| `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 |
|
|
389
|
+
| `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 |
|
|
390
|
+
| `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 |
|
|
391
|
+
| `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) |
|
|
392
|
+
|
|
393
|
+
Every finding has `at` (under the head) and `between` (head to tip), so the viewer points at the screw. The screws,
|
|
394
|
+
nuts, washers and inserts are placed as reference parts from `@rulecad/fixings`: faint in previews, lifted along
|
|
395
|
+
their own axes by `--explode`, checked for overlap with everything but what they are threaded into, moving with the
|
|
396
|
+
part they sit in through every pose, and carried in links. `cad list` counts them and `cad order` names them on the
|
|
397
|
+
step. A `fasten` holds its parts as a fit with `"fastens": true` does and lines their holes up as a holes fit does;
|
|
398
|
+
both older forms still work, and an assembly with no `fasten` checks as before.
|
|
399
|
+
|
|
400
|
+
`cad list` counts every fixing (`fasten.count`): each screw, nut, washer and insert a `fasten` placed (a component's
|
|
401
|
+
too), a motor's mounting screws where a fit that `fastens` holds it (as many as its holes, at the length its mount
|
|
402
|
+
works out for the plate as drawn, taken to a length sold), and a fit that names its `fastener` by hand. They are
|
|
403
|
+
summed by name, which is the thread, length and head (`12 × M3x8 cap`), each with its mass (an estimate from its
|
|
404
|
+
outline, from `@rulecad/fixings`) and the line's, and rounded up to whole packs of `packs.pack` (10, an estimate:
|
|
405
|
+
set your own in `rules/packs.json`) with the spares said. `--json` gives each line as `{ fastener, qty, kind,
|
|
406
|
+
thread, length, head, grams, mass, packs, buy, spare, from }`, the totals add `fixingsGrams` to the machine's mass,
|
|
407
|
+
and the build page's list shows the same.
|
|
408
|
+
|
|
326
409
|
### Joints and poses
|
|
327
410
|
|
|
328
411
|
Things that move (a lid, a hinged screen, a drawer, a ball head) are one assembly with joints, not one assembly per
|
|
@@ -423,15 +506,65 @@ An item can be a motor instead of a printed object: `{ "id": "drive", "motor": {
|
|
|
423
506
|
- `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.
|
|
424
507
|
- `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.
|
|
425
508
|
|
|
509
|
+
### Beams
|
|
510
|
+
|
|
511
|
+
An item can be a beam, a length of an aluminium extrusion, a tube or a bar from `@rulecad/frames`:
|
|
512
|
+
|
|
513
|
+
```json
|
|
514
|
+
{ "id": "x1", "beam": { "profile": "2020-misumi-hfs5", "length": 300 }, "from": [0, 0, 0], "to": [300, 0, 0], "roll": 0 }
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
- `"profile"` names the profile (`2020-misumi-hfs5`, `profile-4040-item-8`, or a set in this workspace's `rules/`).
|
|
518
|
+
`"length"` is mm from end `a` to end `b`, a number or an expression (`"x1.length"`). Placed by its ends, the length
|
|
519
|
+
may be left out: it is the distance from `from` to `to`, and a length that disagrees with them is refused with both.
|
|
520
|
+
`"material"` names a material set in place of the profile's alloy. `"printed": true` is for printed beams, a later
|
|
521
|
+
release: it is refused by name for now.
|
|
522
|
+
- 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
|
|
523
|
+
upright, and `"roll"` turns it about its own axis, in degrees. Or place it with `at` and `rotate` as any item, in its
|
|
524
|
+
own frame: end `a` at the origin, the beam up +z, its top +y. The face names and a picture are in the
|
|
525
|
+
`@rulecad/frames` README ("Face names in an assembly").
|
|
526
|
+
- A beam is bought: drawn faint, never on a plate, on `cad list` by profile and length (`2 × profile-2020-misumi-hfs5
|
|
527
|
+
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
|
|
528
|
+
check by its envelope, a plain box. `cad check` says each beam's mass beside the sheet's, and warns of a length
|
|
529
|
+
longer than the profile is sold in. Its numbers are values: `x1.length`, `x1.width`, `x1.height`, `x1.mass`.
|
|
530
|
+
- `"ops"` lists the operations on it, each placed by an address on the beam and dimensioned from end `a`: `cut`,
|
|
531
|
+
`mitre`, `tap`, `access`, `drill`, `counterbore`, `pocket`, `notch` and `deburr`. `{ "op": "tap", "at": "a", "thread":
|
|
532
|
+
"M5" }` taps end a's bore; `{ "op": "access", "at": "top@-10", "thread": "M5" }` drills a hole for an M5 screw's key 10
|
|
533
|
+
mm from end b; `{ "op": "mitre", "at": "b", "angle": 45, "about": "top" }` mitres end b, the length then measured on
|
|
534
|
+
the long side. Numbers may be expressions. Each is cut into the beam's solid (a mitre into its envelope too), and
|
|
535
|
+
`cad check` reports its findings as `beam.op` (a hole into a slot's lips or across a tapped thread, a tap deeper than
|
|
536
|
+
the bore, a hole too near an end) and thread engagement in the alloy. What each takes is in the `@rulecad/frames`
|
|
537
|
+
README ("Operations").
|
|
538
|
+
- `cad add beam <project>/<assembly> --id x1 --profile 2020-misumi-hfs5 --from 0,0,0 --to 300,0,0 [--roll 90]` adds one.
|
|
539
|
+
|
|
540
|
+
Every beam has addresses, taken wherever an anchor is: an item's `at`, a joint's `parent` or `child`, a `loop`, a
|
|
541
|
+
fit's `a` or `b`, a fit's `access`, and a load's `at`.
|
|
542
|
+
|
|
543
|
+
| Address | Where |
|
|
544
|
+
|---|---|
|
|
545
|
+
| `x1.a`, `x1.b` | The middle of each end, its z out of the end |
|
|
546
|
+
| `x1.a.1`, `x1.b.2` | A bore in an end |
|
|
547
|
+
| `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 |
|
|
548
|
+
| `x1.top@120`, `x1.top@-20`, `x1.top@50%` | 120 mm from end `a`, 20 mm from end `b`, half way along |
|
|
549
|
+
| `x1.top.2@120` | The second slot of a face that has more than one |
|
|
550
|
+
|
|
551
|
+
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
|
|
552
|
+
(`{ "id": "plate", "object": "plate", "at": "x1.top@50%" }`) puts its own origin there, its z out of the face and its
|
|
553
|
+
x along the beam, turned by its `rotate` in that frame; it moves with the beam. A distance past either end is refused
|
|
554
|
+
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
|
|
555
|
+
address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm by default).
|
|
556
|
+
|
|
426
557
|
### Building it
|
|
427
558
|
|
|
428
559
|
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
560
|
|
|
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.
|
|
561
|
+
- `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
562
|
- `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
563
|
- `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`).
|
|
564
|
+
- `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`).
|
|
565
|
+
- `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.
|
|
433
566
|
- `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.
|
|
567
|
+
- `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.
|
|
435
568
|
- 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
569
|
|
|
437
570
|
## Optimised parts
|
package/bin/cad.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import { setVariables, addToAssembly, 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
|
|
@@ -50,9 +50,13 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
50
50
|
cad rules check [set …] rule sets held to what makes them traceable (exit 1 on a failure) [--json]
|
|
51
51
|
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
52
|
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)
|
|
53
|
+
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
54
|
cad values <project>/<object> [names…] the object's variables, resolved [--json]
|
|
54
55
|
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
|
|
56
|
+
cad add fit|joint|item|beam|loop|pose <project>/<assembly> --a … --b … --min … add to an assembly, keeping its layout
|
|
57
|
+
cad add fasten <project>/<assembly> --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2
|
|
58
|
+
a screwed joint (or --holes bracket.body for the part's own holes) [--nut [hex|square|lock]]
|
|
59
|
+
[--washer] [--length 12] [--torque 0.5] [--note …]
|
|
56
60
|
cad why <project>/<object>.<name> what a value reads, down to the rules and their sources [--json] [--depth N]
|
|
57
61
|
cad check <project>/<object> raw numbers in the design, then printability (exit 1 on a failure) [--json: findings as data]
|
|
58
62
|
cad preview <project>/<object> six views as a PNG in .preview/ (prints the path); an assembly with a motor also gets
|
|
@@ -88,16 +92,26 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
88
92
|
.preview/, and any stroke refused [--calibrate: the calibration drawing] [--tol 0.1] [--json]
|
|
89
93
|
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
94
|
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,
|
|
95
|
+
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
|
|
96
|
+
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]
|
|
92
97
|
cad wires <project>/<assembly> the wiring sheet: each wire's length, gauge and ends, written to exports/ [--out wiring.md]
|
|
93
98
|
cad measured <project>/<assembly> <name>=<value> … a measurement, where the estimate was: a rule (x1c.press=0.08) or a
|
|
94
99
|
check's prediction (task.accuracy=0.8): says what moved, and keeps a ledger of predicted
|
|
95
100
|
against measured, shown by cad history [--unit mm] [--source "how"] [--rule "what it is"]
|
|
96
101
|
[--table: what the assembly still assumes, as Markdown; --out MEASURE.md: kept in that file]
|
|
102
|
+
The fixings coupon's rules need no --rule: x1c.pilot_m4, x1c.insert_m3 (and _petg for one
|
|
103
|
+
plastic), x1c.nut_fit, x1c.nut_slip, x1c.thread_gap, x1c.thread_flank (45 or 60)
|
|
104
|
+
The slot coupon's need no --rule: x1c.slot_fit, x1c.printed_slot_fit; a slot measured by
|
|
105
|
+
caliper goes in your copy of its set (slot-8.opening=8.1), checked as a slot
|
|
97
106
|
cad measure <model.stl|3mf> a model from elsewhere, measured: size, the stretches along its length with the same
|
|
98
107
|
cross-section, and each section's shape, with a drawing in .preview/measure/
|
|
99
108
|
[--along x|y|z] [--at 10,50: sections there too] [--line 0.6,2.5;4.6,2.5: where lines
|
|
100
109
|
along it are inside] [--rules <name> --source <url> --licence "…": draft rules]
|
|
110
|
+
cad measure <beam.stl|3mf|section.dxf> --profile <name> a beam's profile from a model of it, or a DXF of its
|
|
111
|
+
section: its outline to rules/outlines/<name>.json, its slots (opening, lip, width,
|
|
112
|
+
depth) and bores as a draft profile set, each slot matched to a known slot family or
|
|
113
|
+
drafted as a new one, and a drawing of what was found [--source <url> --licence "…"]
|
|
114
|
+
[--tol 0.1: how close a slot must be to a family, mm] [--along x|y|z] [--force]
|
|
101
115
|
cad match <project>/<object> <model.stl|3mf> how closely the design matches a model: both ways, signed, with the
|
|
102
116
|
worst places and sections through them [--tol 0.2 (default: the printer's fit)]
|
|
103
117
|
[--place "rz90 t1,2,3": how to lay the model over the design, else it is fitted]
|
|
@@ -118,27 +132,28 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
118
132
|
|
|
119
133
|
// Every command and option there is: a misspelt one is refused by name, not passed over
|
|
120
134
|
const COMMANDS = ['new', 'import-kle', 'clone', 'agents', 'trust', 'rules', 'values', 'set', 'add', 'why', 'check', 'preview', 'animate', 'optimise', 'optimize', 'export',
|
|
121
|
-
'show', 'link', 'status', 'release', 'history', 'diff', 'printed', 'measure', 'measured', 'list', 'wires', 'machine', 'plot', 'plates', 'order', 'match', 'variants', 'compare', 'help'];
|
|
135
|
+
'show', 'link', 'status', 'release', 'history', 'diff', 'printed', 'measure', 'measured', 'list', 'beams', 'wires', 'machine', 'plot', 'plates', 'order', 'match', 'variants', 'compare', 'help'];
|
|
122
136
|
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',
|
|
123
|
-
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
137
|
+
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'profile', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
124
138
|
'sweep', 'tol', 'trailer', 'ttl', 'version', 'watch', 'line',
|
|
125
139
|
'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'
|
|
140
|
+
'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate', 'to', 'roll', // cad add
|
|
141
|
+
'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque']; // cad add fasten
|
|
127
142
|
// 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 …',
|
|
143
|
+
const USAGE = { add: 'fit|joint|item|beam|loop|pose|fasten <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
|
|
129
144
|
optimise: '<project>/<problem>', optimize: '<project>/<problem>', history: '<project>[/<object>]', release: '<project>[/<object>] -m "what changed"',
|
|
130
145
|
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
146
|
|
|
132
147
|
const args = process.argv.slice(2);
|
|
133
148
|
// Options that stand alone. Every other takes the value after it: --name value, or -m for one-letter names
|
|
134
|
-
// (--sweep and --
|
|
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'];
|
|
149
|
+
// (--sweep, --watch and --nut take one or not).
|
|
150
|
+
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
151
|
const opt = (k) => {
|
|
137
152
|
const i = args.findIndex((a) => a === `--${k}` || (k.length === 1 && a === `-${k}`));
|
|
138
153
|
if (i < 0) return undefined;
|
|
139
154
|
if (FLAGS.includes(k)) return true;
|
|
140
155
|
if (args[i + 1] && !args[i + 1].startsWith('--')) return args[i + 1];
|
|
141
|
-
if (['sweep', 'watch'].includes(k)) return true;
|
|
156
|
+
if (['sweep', 'watch', 'nut'].includes(k)) return true;
|
|
142
157
|
throw new Error(`${args[i]} needs a value after it`);
|
|
143
158
|
};
|
|
144
159
|
// The arguments that aren't options or an option's value: cad values keyboard/case depth width --json
|
|
@@ -332,24 +347,36 @@ async function analyses(b, d, tag) {
|
|
|
332
347
|
// cad rules check / draw / draft: rule sets themselves, not a design's use of them
|
|
333
348
|
function ruleSheets(what, names) {
|
|
334
349
|
if (what === 'check') {
|
|
335
|
-
|
|
350
|
+
// a set fails on a finding of level fail; a warning or a note is said and the set still passes
|
|
351
|
+
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));
|
|
336
352
|
if (opt('json')) console.log(JSON.stringify(results.map((r) => ({ name: r.name, findings: r.findings })), null, 2));
|
|
337
353
|
else {
|
|
338
|
-
for (const r of
|
|
339
|
-
console.log(`${results.length - bad.length} of ${results.length} rule sets pass`);
|
|
354
|
+
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})`); }
|
|
355
|
+
console.log(`${results.length - bad.length} of ${results.length} rule sets pass${noted.length ? ` (${noted.length} with something to know)` : ''}`);
|
|
340
356
|
}
|
|
341
357
|
process.exitCode = bad.length ? 1 : 0;
|
|
342
358
|
return;
|
|
343
359
|
}
|
|
344
360
|
const name = names[0];
|
|
345
|
-
if (!name) throw new Error(`usage: cad rules ${what} <set>${what === 'draft' ?
|
|
361
|
+
if (!name) throw new Error(`usage: cad rules ${what} <set>${what === 'draft' ? ` --from <file.pdf>, or cad rules draft ${draftParts().join('|')} <name>` : ''}`);
|
|
346
362
|
if (what === 'draw') { const to = opt('out') || `${name}.svg`; fs.writeFileSync(to, drawSet(name)); return console.log(`drew ${to}: compare it with the datasheet`); }
|
|
347
|
-
|
|
363
|
+
const save = (as, set) => {
|
|
364
|
+
const to = path.join(paths.rules ? paths.rules() : path.join(WS, 'rules'), `${as}.json`);
|
|
365
|
+
if (fs.existsSync(to) && !opt('force')) throw new Error(`${path.relative(WS, to)} already exists (--force replaces it)`);
|
|
366
|
+
fs.mkdirSync(path.dirname(to), { recursive: true }); fs.writeFileSync(to, JSON.stringify(set, null, 2) + '\n');
|
|
367
|
+
return to;
|
|
368
|
+
};
|
|
369
|
+
// cad rules draft profile <name>: every field of the vocabulary for that part, to fill from a sheet
|
|
370
|
+
if (draftParts().includes(name) && !opt('from')) {
|
|
371
|
+
const part = name, as = names[1];
|
|
372
|
+
if (!as) throw new Error(`usage: cad rules draft ${part} <name>`);
|
|
373
|
+
const to = save(as, draftPart(part, as));
|
|
374
|
+
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}`);
|
|
375
|
+
}
|
|
376
|
+
if (!opt('from')) throw new Error(`usage: cad rules draft <name> --from <file.pdf>, or cad rules draft ${draftParts().join('|')} <name>`);
|
|
348
377
|
const { set, found } = draftSet(name, opt('from'));
|
|
349
378
|
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`);
|
|
350
|
-
const to =
|
|
351
|
-
if (fs.existsSync(to) && !opt('force')) throw new Error(`${path.relative(WS, to)} already exists (--force replaces it)`);
|
|
352
|
-
fs.mkdirSync(path.dirname(to), { recursive: true }); fs.writeFileSync(to, JSON.stringify(set, null, 2) + '\n');
|
|
379
|
+
const to = save(name, set);
|
|
353
380
|
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}`);
|
|
354
381
|
}
|
|
355
382
|
|
|
@@ -416,7 +443,12 @@ async function main() {
|
|
|
416
443
|
if (cmd === 'clone') return cloneBoard(ref, pos[2], { source: opt('source'), licence: opt('licence') || opt('license'), force: !!opt('force'), noModels: !!opt('no-models') });
|
|
417
444
|
if (cmd === 'status') return status(ref);
|
|
418
445
|
if (cmd === 'measure') {
|
|
419
|
-
if (!ref) throw new Error('usage: cad measure <model.stl|model.3mf> [--along x] [--at 10,50] [--line 0.6,2.5] [--rules <name>]');
|
|
446
|
+
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>');
|
|
447
|
+
if (opt('profile')) {
|
|
448
|
+
const { measureProfile } = await import('../lib/profilemeasure.mjs');
|
|
449
|
+
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') });
|
|
450
|
+
}
|
|
451
|
+
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');
|
|
420
452
|
const list = (k) => (opt(k) && opt(k) !== true ? String(opt(k)).split(k === 'line' ? ';' : ',').filter(Boolean) : []);
|
|
421
453
|
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') });
|
|
422
454
|
}
|
|
@@ -425,7 +457,7 @@ async function main() {
|
|
|
425
457
|
if (cmd === 'variants') return variants(locate(ref));
|
|
426
458
|
if (cmd === 'compare') return compareVariants(locate(ref), pos[2], pos[3]);
|
|
427
459
|
if (cmd === 'measured') return measuredCommand(ref);
|
|
428
|
-
if (cmd === 'list' || cmd === 'wires') return listCommand(cmd, ref);
|
|
460
|
+
if (cmd === 'list' || cmd === 'wires' || cmd === 'beams') return listCommand(cmd, ref);
|
|
429
461
|
if (cmd === 'machine' || cmd === 'plot') return machineCommand(cmd, ref);
|
|
430
462
|
if (cmd === 'plates' || cmd === 'order') return platesCommand(cmd, ref);
|
|
431
463
|
if (cmd === 'history') return history(ref);
|
|
@@ -489,6 +521,7 @@ async function main() {
|
|
|
489
521
|
? [{ 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
522
|
: check(b.triangles, printer(b, d), { parts: b.parts })),
|
|
491
523
|
...(b.mechanism?.findings || []), // a lamina mechanism's own: it prints free, stops, holds, clears in every state
|
|
524
|
+
...(b.fixings || []), // what v.fixings drew: each hole and seat, what it was drawn to and the rule it rests on
|
|
492
525
|
...(await analyses(b, d, tag)),
|
|
493
526
|
], { 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
527
|
if (b.object.orientation) say(` orientation: ${b.object.orientation}`);
|
|
@@ -560,23 +593,32 @@ async function editVariables(ref) {
|
|
|
560
593
|
console.log(`set ${r.changed.join(', ')} in ${path.relative(WS, r.file)}`);
|
|
561
594
|
}
|
|
562
595
|
|
|
563
|
-
// cad add fit|joint|item|loop|pose <project>/<assembly> --key value …: add to an assembly, keeping its layout
|
|
596
|
+
// cad add fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …: add to an assembly, keeping its layout
|
|
564
597
|
async function editAssembly(what, ref) {
|
|
565
598
|
const list = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => parseValue(x.trim())) : undefined);
|
|
566
599
|
const pick = (keys) => Object.fromEntries(keys.map((k) => [k, typeof opt(k) === 'string' ? parseValue(opt(k)) : undefined]).filter(([, v]) => v !== undefined));
|
|
567
600
|
const text = (keys) => Object.fromEntries(keys.filter((k) => typeof opt(k) === 'string').map((k) => [k, String(opt(k))]));
|
|
601
|
+
// (an item's at is a point, 1,2,3, or an address on a beam: --at x1.top@50%)
|
|
602
|
+
const at = () => (typeof opt('at') !== 'string' ? {} : /^[a-z][\w-]*\./i.test(opt('at')) ? { at: String(opt('at')) } : { at: list('at') });
|
|
568
603
|
let entry;
|
|
569
604
|
if (what === 'fit') entry = { ...text(['a', 'b']), ...pick(['min', 'max']), ...(list('poses') ? { poses: list('poses').map(String) } : {}), ...text(['note', 'label']) };
|
|
570
605
|
else if (what === 'joint') entry = { ...text(['id', 'type', 'parent', 'child', 'label', 'follow']), ...pick(['min', 'max', 'value', 'ratio']) };
|
|
571
|
-
else if (what === '
|
|
606
|
+
else if (what === 'beam') {
|
|
607
|
+
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');
|
|
608
|
+
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') } : {}) };
|
|
609
|
+
} else if (what === 'item') entry = { ...text(['id', 'object', 'assembly', 'variant']), ...at(), ...(list('rotate') ? { rotate: list('rotate') } : {}),
|
|
572
610
|
...(typeof opt('set') === 'string' ? { set: Object.fromEntries(sets() && Object.entries(sets()).map(([k, v]) => [k, parseValue(v)])) } : {}) };
|
|
573
611
|
else if (what === 'loop') entry = text(['a', 'b', 'label']);
|
|
612
|
+
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 …]
|
|
613
|
+
const names = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => x.trim()).filter(Boolean) : undefined);
|
|
614
|
+
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']) };
|
|
615
|
+
}
|
|
574
616
|
else if (what === 'pose') {
|
|
575
617
|
const pairs = positional().slice(3);
|
|
576
618
|
if (typeof opt('name') !== 'string' || !pairs.length) throw new Error('usage: cad add pose <project>/<assembly> --name open hinge=90 [joint=value …]');
|
|
577
619
|
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 …');
|
|
579
|
-
const r = addToAssembly(ref, what, entry);
|
|
620
|
+
} else throw new Error('usage: cad add fit|joint|item|beam|loop|pose|fasten <project>/<assembly> --key value …');
|
|
621
|
+
const r = addToAssembly(ref, what === 'beam' ? 'item' : what, entry);
|
|
580
622
|
if (opt('json')) return console.log(JSON.stringify({ ...r, added: entry }));
|
|
581
623
|
console.log(`added ${/^[aeiou]/.test(what) ? "an" : "a"} ${what} to ${path.relative(WS, r.file)}`);
|
|
582
624
|
}
|
|
@@ -992,6 +1034,13 @@ async function listCommand(what, ref) {
|
|
|
992
1034
|
const { shoppingList, listText } = await import('../lib/list.mjs'), l = shoppingList(s);
|
|
993
1035
|
return console.log(opt('json') ? JSON.stringify(l, null, 2) : listText(ref, l));
|
|
994
1036
|
}
|
|
1037
|
+
if (what === 'beams') {
|
|
1038
|
+
const { writeBeamSheets } = await import('../lib/beams.mjs'), sheets = writeBeamSheets(s);
|
|
1039
|
+
if (opt('json')) return console.log(JSON.stringify(sheets.map((x) => ({ ...x, file: path.relative(WS, x.file) })), null, 2));
|
|
1040
|
+
if (!sheets.length) return console.log(`${ref} has no beams`);
|
|
1041
|
+
for (const x of sheets) say(` mark ${x.mark} (${x.items.join(', ')}), 1:${x.scale}: ${path.relative(WS, x.file)}`);
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
995
1044
|
const { wiresFor } = await import('../lib/assembly.mjs'), { wiringSheet } = await import('../lib/wires.mjs'), rows = wiresFor(s);
|
|
996
1045
|
if (opt('json')) return console.log(JSON.stringify(rows.map(({ route, ...r }) => r), null, 2));
|
|
997
1046
|
if (!rows.length) return console.log(`${ref} has no "wires"`);
|