@rulecad/cad 0.7.68 → 0.7.70
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/CHANGELOG.md +41 -0
- package/README.md +5 -2
- package/bin/cad.mjs +28 -24
- package/lib/edit.mjs +53 -13
- package/lib/fasten.mjs +19 -8
- package/lib/order.mjs +1 -1
- package/lib/pins.mjs +2 -1
- package/package.json +4 -4
- package/schemas/assembly.schema.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,47 @@ print (a hole's diameter, a seat's depth, a part's outline). Each release lists
|
|
|
5
5
|
its reason. A **fasten** is an entry in an assembly's `"fasten"` list: one screwed joint, naming the screw by thread
|
|
6
6
|
and head, the parts it passes through and the part it ends in.
|
|
7
7
|
|
|
8
|
+
## 0.7.70: printed bolts into slot nuts, a slotted snap pot
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **A printed bolt into a slot nut** (issue 305): its length is now any whole millimetre between the nut's thread and
|
|
12
|
+
the slot's floor, as a printed bolt's is everywhere else, and `fasten.length` says "the shortest that fits (a printed
|
|
13
|
+
bolt is printed to any whole millimetre)", not "the shortest sold". A 10 mm plate on a 3030's slot, where no M6 is
|
|
14
|
+
sold from 16.4 to 18.7 mm, takes an M6x17 printed bolt.
|
|
15
|
+
- **A torque given for a printed bolt** is worded as a turn by hand, not a tightening: `fasten.seat` says "turned by
|
|
16
|
+
hand to 1 N m, it clamps with about 833.3 N (T = K d F, fixings.nut_factor 0.2 for steel threads: an estimate for a
|
|
17
|
+
printed one)", and `cad order` says "to 1 N m and no further (a printed bolt, turned by hand, not tightened)". A new
|
|
18
|
+
finding, `fasten.torque`, holds that clamp against what the bolt breaks at, about twice over: an M6 printed bolt in
|
|
19
|
+
PLA breaks at 625.2 N, so 1 N m fails and names 0.37 N m as the most (rounded down, so it passes its own check). The seat's values no longer carry a
|
|
20
|
+
tightening torque for a printed bolt.
|
|
21
|
+
|
|
22
|
+
- **Pins lying on their side** (issue 306): a pin in teardrop holes, as `v.fixings.pinHole` draws one lying on its
|
|
23
|
+
side, is found and checked as a round one is. It already was: `holesIn` leaves a teardrop's roof out of the round
|
|
24
|
+
it fits. A test now holds it (press, slip and snap sockets, along x and along y, blind, and the failures by name),
|
|
25
|
+
and the README says so.
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- The bench project `enclosures` has a `slotted` variant of `snap-pot`, its lid's skirt in 16 fingers (issue 309), and
|
|
30
|
+
the assembly `snap-pot-slotted-closed`.
|
|
31
|
+
|
|
32
|
+
## 0.7.69: --dry-run never writes
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- `--dry-run` never writes. It was a flag every command accepted, and four that did not handle it wrote the file
|
|
37
|
+
anyway: `cad set <project>/<object>` (an object's variables), `cad add fasten --from-fits`, `cad frame --expand` and
|
|
38
|
+
`cad frame --size --write`. Each now runs every check and writes nothing on a dry run, saying what it would write;
|
|
39
|
+
with `--json` it answers `written: false, dryRun: true`. Any other command given `--dry-run` (`cad measured`,
|
|
40
|
+
`cad check`, `cad export` and the rest) refuses it by name and runs nothing, listing the commands that take one.
|
|
41
|
+
`setVariables(ref, changes, { dryRun })` and `fastenFromFitsEdit(ref, found, { dryRun })` in `lib/edit.mjs` take it
|
|
42
|
+
too, and `setVariables` now checks the edit before it writes, so a refused one never touches the file.
|
|
43
|
+
- `cad new <project>/<object>` takes `--dry-run` and `--json` as the other edits do. Before, a dry run made the
|
|
44
|
+
object's files anyway, and `--json` printed a line of words. Now a dry run writes nothing and says what it would make;
|
|
45
|
+
`--json` answers `{ command, file, written, dryRun, made, changes, findings }`; an object already there is refused
|
|
46
|
+
as `object.exists` and a bad name as `edit.name`. A project made for a new object is made as `cad new <project>`
|
|
47
|
+
makes one, with its `$schema`. A program can call it as `newObject(ref, { dryRun })` from `lib/edit.mjs`.
|
|
48
|
+
|
|
8
49
|
## 0.7.68: the actuator printed in place (#162)
|
|
9
50
|
|
|
10
51
|
### Added
|
package/README.md
CHANGED
|
@@ -472,6 +472,7 @@ starts and stops. From that the check says:
|
|
|
472
472
|
| `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 |
|
|
473
473
|
| `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 |
|
|
474
474
|
| `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 |
|
|
475
|
+
| `fasten.torque` | A printed bolt given a `torque`: the clamp it is turned to (T = K d F with steel's nut factor, an estimate for a printed thread) held against what the bolt breaks at, about twice over (`fixings.load_margin`); a turn that would break it fails, naming the most to turn it to |
|
|
475
476
|
| `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 |
|
|
476
477
|
| `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) |
|
|
477
478
|
|
|
@@ -514,7 +515,7 @@ draws its hole or pocket from the printer's rules:
|
|
|
514
515
|
```
|
|
515
516
|
|
|
516
517
|
- **Pins** (`fit.pin`): a snap pin, a steel dowel, a length of filament or a printed pin. `cad check` finds round holes
|
|
517
|
-
in part a whose axis goes on into part b, holds each to the hole fixings draws for that pin (a snap pin's socket, a
|
|
518
|
+
in part a, standing or lying on their side as teardrops (the roof is left out of the round), whose axis goes on into part b, holds each to the hole fixings draws for that pin (a snap pin's socket, a
|
|
518
519
|
plain pin's press or slip hole), and measures the parts along the axis: a pin too long or too short for its parts
|
|
519
520
|
fails by name, and so do fewer holes than `count`. `load` (across the joint) and `pull` (along the pins) are held
|
|
520
521
|
to about twice the margin.
|
|
@@ -523,7 +524,9 @@ draws its hole or pocket from the printer's rules:
|
|
|
523
524
|
their pull, across `gap` where something lies between.
|
|
524
525
|
- **Printed bolts** are a fasten's: `"screw": "M8x20 hex printed"`. Below the printer's smallest thread it is refused
|
|
525
526
|
by name (M5 at 0.2 mm layers names M6); its load is held to the plastic's strength by how it prints, and no wrench
|
|
526
|
-
torque is said, since a printed thread is done up by hand.
|
|
527
|
+
torque is said, since a printed thread is done up by hand. Its length is any whole millimetre that fits, into a
|
|
528
|
+
slot nut too, where a bought screw is held to the lengths sold. A `torque` given for it is a turn by hand, held to
|
|
529
|
+
what the bolt breaks at (`fasten.torque`), and `cad order` says it as a turn to that torque and no further.
|
|
527
530
|
|
|
528
531
|
`cad list` lists pins (printed, cut or bought) and magnets (bought) with their grams, and printed bolts among the
|
|
529
532
|
printed parts; `cad order` names each on its step. A fastener given as text (`"fastener": "push pin"`) is listed as
|
package/bin/cad.mjs
CHANGED
|
@@ -20,7 +20,7 @@ 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, fastenFromFitsEdit, parseValue, parseSetting, newProject, setProject, newAssembly, setInAssembly, removeFromAssembly, moveInAssembly } from '../lib/edit.mjs';
|
|
23
|
+
import { setVariables, addToAssembly, fastenFromFitsEdit, parseValue, parseSetting, newProject, setProject, newAssembly, newObject, setInAssembly, removeFromAssembly, moveInAssembly } 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';
|
|
@@ -57,7 +57,7 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
57
57
|
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)
|
|
58
58
|
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
|
|
59
59
|
cad values <project>/<object> [names…] the object's variables, resolved [--json]
|
|
60
|
-
cad set <project>/<object> name=value … change variables, keeping the file's layout [--unit, --rule, --label, --new to add one]
|
|
60
|
+
cad set <project>/<object> name=value … change variables, keeping the file's layout [--unit, --rule, --label, --new to add one] [--dry-run]
|
|
61
61
|
cad set <project>/<assembly> <address>=<value> … change an assembly's fields: an entry's by its id or place (x1.at=[0,0,20],
|
|
62
62
|
joins.3.kind=bracket), or its own (title=…, frame.join.fitting=printed, frame.inside=[300,300,400]);
|
|
63
63
|
a value is JSON, a [list, of, names] or text
|
|
@@ -69,7 +69,8 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
69
69
|
cad remove <project>/<assembly> <id | list.n | id.field> take an entry or a field out; refused, naming them, while other
|
|
70
70
|
entries name it, unless --with-refs takes them out too
|
|
71
71
|
Every edit (new, set, add, move, remove): checked against the schema and what it could break before it is written,
|
|
72
|
-
refused by name with nothing written; --dry-run shows it without writing
|
|
72
|
+
refused by name with nothing written; --dry-run shows it without writing (also add fasten --from-fits, frame --expand and
|
|
73
|
+
frame --size --write; any other command refuses --dry-run); --json says what changed, and the checks
|
|
73
74
|
cad add fasten <project>/<assembly> --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2
|
|
74
75
|
a screwed joint (or --holes bracket.body for the part's own holes) [--nut [hex|square|lock]]
|
|
75
76
|
[--washer] [--length 12] [--torque 0.5] [--note …]
|
|
@@ -115,9 +116,9 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
115
116
|
cad kit <project>/<assembly> the folder to build it from without the model, in exports/: README.md (checks, what to buy and print, cut list, drilling, the build step by step), buy.csv, the plates' 3MFs, the jigs, each beam's sheet [--pictures] [--json]
|
|
116
117
|
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
|
|
117
118
|
cad frame <project>/<assembly> a generated frame ("frame": { "kind": "box", "inside": [..] }): its size, its beams by length, its joins and ends
|
|
118
|
-
--expand: written into the assembly as its beams, joins and end fittings, to edit by hand [--json]
|
|
119
|
+
--expand: written into the assembly as its beams, joins and end fittings, to edit by hand [--json] [--dry-run]
|
|
119
120
|
--size: any frame's beams, by group, each given the lightest profile from frame.size.profiles that meets
|
|
120
|
-
its limits, as a table naming the limit that set each; --write writes the profiles in [--json]
|
|
121
|
+
its limits, as a table naming the limit that set each; --write writes the profiles in [--json] [--dry-run]
|
|
121
122
|
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]
|
|
122
123
|
--jigs: the jigs its beams take, as a plate in exports/ (a drill guide per distinct hole across a beam, a tap
|
|
123
124
|
guide per tapped end, a cut-length stop per length, a squaring corner per square join), each marked with its beam [--preview]
|
|
@@ -168,6 +169,10 @@ const OPTIONS = ['table', 'calibrate', 'check', 'turns', 'preview', 'gap', 'no-s
|
|
|
168
169
|
'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque', 'from-fits', // cad add fasten
|
|
169
170
|
'kind', 'fitting', // cad add join
|
|
170
171
|
'title', 'description', 'printer', 'frame', 'inside', 'outside', 'join', 'feet', 'caps', 'with-refs', 'mass', 'joint']; // cad new, cad remove, cad add load
|
|
172
|
+
// The commands that take --dry-run (each checks its edit and writes nothing); any other is refused with it, as a flag
|
|
173
|
+
// it passed over would let the command write
|
|
174
|
+
const takesDryRun = (cmd) => ['new', 'set', 'add', 'remove', 'move', 'release'].includes(cmd) || (cmd === 'frame' && (opt('expand') || (opt('size') && opt('write'))));
|
|
175
|
+
const DRY_RUNS = 'the commands that take one are cad new, set, add, remove, move, release, frame --expand and frame --size --write';
|
|
171
176
|
// What a command takes, where that isn't <project>/<object>
|
|
172
177
|
const USAGE = { add: 'fit|joint|item|beam|loop|pose|fasten|join|guide|load|wire <project>/<assembly> --key value … [field=value …]', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …, <project>/<assembly> <address>=<value> …, or <project> field=value …',
|
|
173
178
|
remove: '<project>/<assembly> <id | list.n | id.field> [--with-refs] [--dry-run]', move: '<project>/<assembly> <id> --at x,y,z | --to <address> [--rotate x,y,z] [--dry-run]',
|
|
@@ -427,23 +432,12 @@ async function main() {
|
|
|
427
432
|
const odd = args.find((a) => a.startsWith('--') && !OPTIONS.includes(a.slice(2)));
|
|
428
433
|
if (odd) { const guess = near(odd.slice(2), OPTIONS); throw new Error(`no option ${odd}${guess ? ` (did you mean --${guess}?)` : ''}: cad help lists them`); }
|
|
429
434
|
if (configError) throw configError;
|
|
435
|
+
if (opt('dry-run') && !takesDryRun(cmd)) throw new Error(`cad ${cmd}${opt('size') ? ' --size' : ''} takes no --dry-run, so nothing is run: ${DRY_RUNS}`);
|
|
430
436
|
|
|
431
437
|
if (cmd === 'new' && (opt('assembly') || !String(ref || '').includes('/'))) return newCommand(ref ?? (typeof opt('assembly') === 'string' ? opt('assembly') : undefined));
|
|
432
|
-
if (cmd === 'new') {
|
|
433
|
-
const [project, name] = String(ref
|
|
434
|
-
|
|
435
|
-
const dir = paths.project(project), objects = path.join(dir, 'objects');
|
|
436
|
-
fs.mkdirSync(objects, { recursive: true });
|
|
437
|
-
const pj = path.join(dir, 'project.json');
|
|
438
|
-
const p = fs.existsSync(pj) ? JSON.parse(fs.readFileSync(pj, 'utf8')) : { name: project, description: '', material: 'PLA', objects: [] };
|
|
439
|
-
for (const ext of ['js', 'json']) {
|
|
440
|
-
const to = path.join(objects, `${name}.${ext}`);
|
|
441
|
-
if (fs.existsSync(to)) throw new Error(`${path.relative(WS, to)} already exists`);
|
|
442
|
-
fs.writeFileSync(to, fs.readFileSync(path.join(TOOL, 'templates', `object.${ext}`), 'utf8').replaceAll('NAME', name));
|
|
443
|
-
}
|
|
444
|
-
if (!p.objects.includes(name)) p.objects.push(name);
|
|
445
|
-
fs.writeFileSync(pj, JSON.stringify(p, null, 2) + '\n');
|
|
446
|
-
return console.log(`made projects/${project}/objects/${name}.{js,json}`);
|
|
438
|
+
if (cmd === 'new') { // an object, from the template; --dry-run and --json as the other edits
|
|
439
|
+
const r = newObject(ref, { dryRun: !!opt('dry-run') }), [project, name] = String(ref).split('/');
|
|
440
|
+
return edited(r, 'new', {}, `${r.dryRun ? 'would make' : 'made'} projects/${project}/objects/${name}.{js,json}`);
|
|
447
441
|
}
|
|
448
442
|
|
|
449
443
|
if (cmd === 'rules' && ['check', 'draw', 'draft'].includes(ref)) return ruleSheets(ref, pos.slice(2));
|
|
@@ -631,9 +625,9 @@ async function editVariables(ref) {
|
|
|
631
625
|
const extra = Object.fromEntries(['unit', 'rule', 'label'].filter((k) => typeof opt(k) === 'string').map((k) => [k, opt(k)]));
|
|
632
626
|
if (pairs.length > 1 && (extra.rule || extra.label)) throw new Error(`--${extra.rule ? 'rule' : 'label'} describes one variable: set ${pairs.map((p) => p.split('=')[0]).join(' and ')} one at a time`);
|
|
633
627
|
const changes = Object.fromEntries(pairs.map((p) => { const i = p.indexOf('='); return [p.slice(0, i).trim(), { value: parseValue(p.slice(i + 1).trim()), ...extra }]; }));
|
|
634
|
-
const r = await setVariables(ref, changes, { create: !!opt('new') });
|
|
628
|
+
const r = await setVariables(ref, changes, { create: !!opt('new'), dryRun: !!opt('dry-run') });
|
|
635
629
|
if (opt('json')) return console.log(JSON.stringify(r));
|
|
636
|
-
console.log(`set ${r.changed.join(', ')} in ${
|
|
630
|
+
console.log(`${r.dryRun ? `dry run, nothing written: would set` : 'set'} ${r.changed.join(', ')} in ${rel(r.file)}`);
|
|
637
631
|
}
|
|
638
632
|
|
|
639
633
|
// cad add fit|joint|item|loop|pose|fasten|join <project>/<assembly> --key value …: add to an assembly, keeping its layout
|
|
@@ -654,9 +648,10 @@ async function editAssembly(what, ref) {
|
|
|
654
648
|
else if (what === 'loop') entry = text(['a', 'b', 'label']);
|
|
655
649
|
else if (what === 'fasten' && opt('from-fits')) { // a holes fit and a fit that fastens, put as one fasten
|
|
656
650
|
const s = await buildAssembly(ref), { fastenFromFits } = await import('../lib/fasten.mjs');
|
|
657
|
-
const r = fastenFromFitsEdit(ref, fastenFromFits(s), { screw: typeof opt('screw') === 'string' ? opt('screw') : undefined });
|
|
651
|
+
const r = fastenFromFitsEdit(ref, fastenFromFits(s), { screw: typeof opt('screw') === 'string' ? opt('screw') : undefined, dryRun: !!opt('dry-run') });
|
|
658
652
|
if (opt('json')) return console.log(JSON.stringify(r));
|
|
659
|
-
|
|
653
|
+
if (r.dryRun) console.log('dry run, nothing written:');
|
|
654
|
+
for (const x of r.added) console.log(`${r.dryRun ? 'would add' : 'added'} a fasten to ${rel(r.file)} in place of its holes fit and its fit that fastens: ${JSON.stringify(x)}`);
|
|
660
655
|
return console.log(`check its screws: cad check ${ref}`);
|
|
661
656
|
}
|
|
662
657
|
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 …]
|
|
@@ -1201,6 +1196,11 @@ async function frameCommand(ref) {
|
|
|
1201
1196
|
const rows = r.rows, out = { assembly: ref, ok: r.ok, total: r.total, drawn: r.drawn, tried: r.tried, search: r.search, groups: rows, limits: r.limits };
|
|
1202
1197
|
if (opt('write')) {
|
|
1203
1198
|
if (!r.ok) throw new Error(`${ref}: no profile in the list meets every limit, so nothing is written (cad frame ${ref} --size says how near it comes)`);
|
|
1199
|
+
if (opt('dry-run')) { // the sizing and the check above, nothing written
|
|
1200
|
+
if (opt('json')) return console.log(JSON.stringify({ ...out, file: rel(file), written: false, dryRun: true }, null, 2));
|
|
1201
|
+
console.log(sizingText(r).join('\n'));
|
|
1202
|
+
return console.log(`dry run, nothing written: would write ${rel(file)}`);
|
|
1203
|
+
}
|
|
1204
1204
|
fs.writeFileSync(file, `${JSON.stringify(writeSizing(raw, raw.frame?.kind != null ? expandFrame(raw, s.num).a : raw, r), null, 2)}\n`);
|
|
1205
1205
|
if (opt('json')) return console.log(JSON.stringify({ ...out, file: path.relative(WS, file) }, null, 2));
|
|
1206
1206
|
console.log(sizingText(r).join('\n'));
|
|
@@ -1211,6 +1211,10 @@ async function frameCommand(ref) {
|
|
|
1211
1211
|
}
|
|
1212
1212
|
if (raw.frame?.kind == null) throw new Error(`${ref} asks for no generated frame: give it "frame": { "kind": "box", "inside": [300, 300, 350], "profile": "2020-misumi-hfs5", "join": "blind" }`);
|
|
1213
1213
|
const s = await buildAssembly(ref), m = s.generated, out = expandFrame(raw, s.num).a;
|
|
1214
|
+
if (opt('expand') && opt('dry-run')) {
|
|
1215
|
+
if (opt('json')) return console.log(JSON.stringify({ assembly: ref, file: rel(file), written: false, dryRun: true, frame: m, expanded: out }, null, 2));
|
|
1216
|
+
return console.log(`dry run, nothing written: would write ${rel(file)}: the ${m.kind} as ${m.beams.length + (m.moving ? 1 : 0)} beams, ${m.joins.length} joins and ${m.ends.length + m.panels.length} fittings`);
|
|
1217
|
+
}
|
|
1214
1218
|
if (opt('expand')) {
|
|
1215
1219
|
fs.writeFileSync(file, `${JSON.stringify(out, null, 2)}\n`);
|
|
1216
1220
|
if (opt('json')) return console.log(JSON.stringify({ assembly: ref, file: path.relative(WS, file), frame: m }, null, 2));
|
package/lib/edit.mjs
CHANGED
|
@@ -16,21 +16,22 @@ import { plasticNamed } from './fittings.mjs';
|
|
|
16
16
|
// A value from the command line: a number if it is one, otherwise an expression (or a name) as text
|
|
17
17
|
export const parseValue = (s) => (s === undefined ? undefined : /^-?(\d+\.?\d*|\.\d+)(e-?\d+)?$/i.test(String(s).trim()) ? Number(s) : String(s));
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// The edited text, parsed and held to its schema: refused by name, nothing written
|
|
20
|
+
function checked(file, text, kind) {
|
|
20
21
|
let json;
|
|
21
22
|
try { json = JSON.parse(text); } catch (e) { throw new CadError('edit.broken', `the edit would break ${file}'s JSON: ${e.message}`, { file }); }
|
|
22
23
|
const problems = validate(json, schema(kind));
|
|
23
24
|
if (problems.length) throw new CadError('schema', `${path.basename(file)}: ${problems[0].path}: ${problems[0].message}`, { file, path: problems[0].path });
|
|
24
|
-
fs.writeFileSync(file, text);
|
|
25
25
|
return json;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Set variables of an object: { name: value }, each with optional unit, rule, label; new ones only with create.
|
|
30
30
|
* @param {string} ref project/object @param {Record<string, { value?: any, unit?: string, rule?: string, label?: string }>} changes
|
|
31
|
-
*
|
|
31
|
+
* Every check runs before anything is written; dryRun runs them all and writes nothing.
|
|
32
|
+
* @param {{ create?: boolean, dryRun?: boolean }} [options] @returns {Promise<{ file: string, changed: string[], written: boolean, dryRun?: true }>}
|
|
32
33
|
*/
|
|
33
|
-
export async function setVariables(ref, changes, { create = false } = {}) {
|
|
34
|
+
export async function setVariables(ref, changes, { create = false, dryRun = false } = {}) {
|
|
34
35
|
const d = locate(ref), before = fs.readFileSync(d.json, 'utf8');
|
|
35
36
|
let text = before;
|
|
36
37
|
for (const [name, c] of Object.entries(changes)) {
|
|
@@ -40,8 +41,8 @@ export async function setVariables(ref, changes, { create = false } = {}) {
|
|
|
40
41
|
if (!exists) { text = setAt(text, ['variables', name], { value: c.value, ...(c.unit !== undefined ? { unit: c.unit } : {}), rule: c.rule, ...(c.label ? { label: c.label } : {}) }); continue; }
|
|
41
42
|
for (const k of ['value', 'unit', 'rule', 'label']) if (c[k] !== undefined) text = setAt(text, ['variables', name, k], c[k]);
|
|
42
43
|
}
|
|
43
|
-
const json =
|
|
44
|
-
try { // the variables must still resolve: an unknown name or a loop
|
|
44
|
+
const json = checked(d.json, text, 'object');
|
|
45
|
+
try { // the variables must still resolve: an unknown name or a loop is refused (the edit changes no uses, so the sets are the file's own)
|
|
45
46
|
const { values } = resolve(json, { sets: (await objectSets(d, readObject(d))).sets });
|
|
46
47
|
// and each changed value must lie within the variable's own range, where it has one (a tweak's min and max)
|
|
47
48
|
for (const name of Object.keys(changes)) {
|
|
@@ -50,8 +51,10 @@ export async function setVariables(ref, changes, { create = false } = {}) {
|
|
|
50
51
|
const lo = typeof t.min === 'number' ? t.min : -Infinity, hi = typeof t.max === 'number' ? t.max : Infinity;
|
|
51
52
|
if (v < lo || v > hi) throw new CadError('edit.range', `${name} = ${v} is outside its range, ${t.min ?? '…'} to ${t.max ?? '…'} (change the range first if it should go there)`, { file: d.json, path: `variables.${name}` });
|
|
52
53
|
}
|
|
53
|
-
} catch (e) {
|
|
54
|
-
|
|
54
|
+
} catch (e) { throw Object.assign(e, { file: d.json, message: `not changed: ${e.message}` }); }
|
|
55
|
+
const written = !dryRun && text !== before;
|
|
56
|
+
if (written) fs.writeFileSync(d.json, text);
|
|
57
|
+
return { file: d.json, changed: Object.keys(changes), written, ...(dryRun ? { dryRun: true } : {}) };
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
const assemblyFile = (ref) => {
|
|
@@ -92,10 +95,11 @@ export function addToAssembly(ref, what, entry, { dryRun = false } = {}) {
|
|
|
92
95
|
* Put a fasten in place of each holes fit and the fit that fastens the same two items (as lib/fasten.mjs's fastenFromFits
|
|
93
96
|
* finds them): the holes fit goes, the fit that fastens goes too, or keeps its gap range (min, max) with "fastens",
|
|
94
97
|
* "fastener" and "count" taken off, and the fasten is added. A screw given replaces the one found.
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
98
|
+
* dryRun checks it all and writes nothing.
|
|
99
|
+
* @param {string} ref project/assembly @param {{ fasten: object, holes: number, fastens: number }[]} found @param {{ screw?: string, dryRun?: boolean }} [options]
|
|
100
|
+
* @returns {{ file: string, added: object[], written: boolean, dryRun?: true }}
|
|
97
101
|
*/
|
|
98
|
-
export function fastenFromFitsEdit(ref, found, { screw } = {}) {
|
|
102
|
+
export function fastenFromFitsEdit(ref, found, { screw, dryRun = false } = {}) {
|
|
99
103
|
const file = assemblyFile(ref);
|
|
100
104
|
if (!found.length) throw new CadError('edit.nothing', `${ref} has no holes fit with a fit that fastens the same two items (and no fasten for them yet): nothing to put a fasten in place of`, { file });
|
|
101
105
|
let text = fs.readFileSync(file, 'utf8');
|
|
@@ -109,8 +113,9 @@ export function fastenFromFitsEdit(ref, found, { screw } = {}) {
|
|
|
109
113
|
if (getAt(text, ['fasten']) === undefined) text = setAt(text, ['fasten'], []);
|
|
110
114
|
const added = found.map((g) => ({ ...g.fasten, ...(screw ? { screw } : {}) }));
|
|
111
115
|
for (const x of added) text = appendAt(text, ['fasten'], x);
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
checked(file, text, 'assembly');
|
|
117
|
+
if (!dryRun) fs.writeFileSync(file, text);
|
|
118
|
+
return { file, added, written: !dryRun, ...(dryRun ? { dryRun: true } : {}) };
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
// ---------- the workspace's own files: projects and assemblies, made, changed, moved and removed ----------
|
|
@@ -552,6 +557,41 @@ export function setProject(project, changes, { dryRun = false } = {}) {
|
|
|
552
557
|
return finish({ file, before, text, kind: 'project', changes: done, dryRun, findings: projectFindings(JSON.parse(text), project) });
|
|
553
558
|
}
|
|
554
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Make an object from the kit's template: projects/<project>/objects/<name>.js and .json, listed in its project's
|
|
562
|
+
* objects; its project is made first where there is none (PLA, as cad new <project> makes one). With dryRun it writes
|
|
563
|
+
* nothing and says what it would make, in the shape the other edits answer in. Refused by name: a name not in lower
|
|
564
|
+
* case with dashes, an object already there.
|
|
565
|
+
* @param {string} ref project/object @param {{ dryRun?: boolean }} [options]
|
|
566
|
+
*/
|
|
567
|
+
export function newObject(ref, { dryRun = false } = {}) {
|
|
568
|
+
const [project, name] = String(ref || '').split('/');
|
|
569
|
+
if (!NAME.test(project || '') || !NAME.test(name || '')) throw new CadError('edit.name', `an object is <project>/<name>, each lower case with dashes (got ${JSON.stringify(ref)})`);
|
|
570
|
+
const objects = path.join(paths.project(project), 'objects'), pj = projectFile(project);
|
|
571
|
+
const files = ['js', 'json'].map((ext) => path.join(objects, `${name}.${ext}`));
|
|
572
|
+
const there = files.find((f) => fs.existsSync(f));
|
|
573
|
+
if (there) throw new CadError('object.exists', `projects/${project}/objects/${path.basename(there)} is already there: change its variables with cad set ${ref} name=value`, { file: there });
|
|
574
|
+
const texts = ['js', 'json'].map((ext) => fs.readFileSync(new URL(`../templates/object.${ext}`, import.meta.url), 'utf8').replaceAll('NAME', name));
|
|
575
|
+
const object = JSON.parse(texts[1]);
|
|
576
|
+
const problems = validate(object, schema('object'));
|
|
577
|
+
if (problems.length) throw new CadError('schema', `not made: ${name}.json: ${problems[0].path}: ${problems[0].message}`, { file: files[1], path: problems[0].path });
|
|
578
|
+
// its project: made where there is none, else the object added to its list (keeping the file's layout)
|
|
579
|
+
const made = fs.existsSync(pj) ? null : newProject(project, { dryRun: true });
|
|
580
|
+
const before = made ? '' : fs.readFileSync(pj, 'utf8');
|
|
581
|
+
let text = made ? laidOut(made.changes[0].after) : before, listed = [];
|
|
582
|
+
const own = JSON.parse(text);
|
|
583
|
+
if (!Array.isArray(own.objects)) { text = setAt(text, ['objects'], [name]); listed = [{ op: 'add', path: 'objects.0', after: name }]; }
|
|
584
|
+
else if (!own.objects.includes(name)) { text = appendAt(text, ['objects'], name); listed = [{ op: 'add', path: `objects.${own.objects.length}`, after: name }]; }
|
|
585
|
+
const changes = [...(made ? made.changes : []), ...files.map((f, i) => ({ op: 'make', path: `projects/${project}/objects/${path.basename(f)}`, ...(i === 1 ? { after: object } : {}) })), ...listed];
|
|
586
|
+
const findings = [...(made ? made.findings.filter((f) => f.code !== 'schema') : []), { level: 'pass', text: 'matches the object schema', code: 'schema' }];
|
|
587
|
+
if (!dryRun) {
|
|
588
|
+
fs.mkdirSync(objects, { recursive: true });
|
|
589
|
+
files.forEach((f, i) => fs.writeFileSync(f, texts[i]));
|
|
590
|
+
if (text !== before) fs.writeFileSync(pj, text);
|
|
591
|
+
}
|
|
592
|
+
return { file: files[1], written: !dryRun, ...(dryRun ? { dryRun: true } : {}), made: [...(made ? [pj] : []), ...files], changes, findings };
|
|
593
|
+
}
|
|
594
|
+
|
|
555
595
|
/**
|
|
556
596
|
* Make an assembly: projects/<project>/assemblies/<name>.json, empty (items: []) or a generated frame, checked as it
|
|
557
597
|
* is made; its project is made first where there is none, with the material and printer given for it (checked as cad new
|
package/lib/fasten.mjs
CHANGED
|
@@ -767,11 +767,14 @@ export function fastenOf(s, worlds, opts = {}) {
|
|
|
767
767
|
sc.grip = r3(grip);
|
|
768
768
|
let pick = null, none = null, need = null;
|
|
769
769
|
if (end.slot) { // the shortest sold length with a hex nut's height of thread in the slot nut, its tip short of the slot's floor
|
|
770
|
-
const
|
|
770
|
+
const hexH = fx.figures.nut_height?.value;
|
|
771
771
|
need = r3(hexH ? Math.min(end.thread, hexH) : end.thread);
|
|
772
|
-
const lo = end.zThr + need - zHead, hi = end.floor - FASTEN.floor.value - zHead
|
|
772
|
+
const lo = end.zThr + need - zHead, hi = end.floor - FASTEN.floor.value - zHead;
|
|
773
|
+
// (a printed bolt is printed to any whole millimetre: every one from the shortest up is "sold")
|
|
774
|
+
const sold = fx.printed ? Array.from({ length: Math.max(0, Math.floor(hi + EPS) - Math.ceil(lo - EPS) + 1) }, (_, i) => Math.ceil(lo - EPS) + i) : fx.figures.lengths?.value || [], L0 = sold.find((l) => l >= lo - EPS && l <= hi + EPS);
|
|
773
775
|
end.need = need; end.window = [r3(lo), r3(hi)];
|
|
774
776
|
if (L0) pick = { name: F.screwModel(fx, { length: L0, head: form }).name, length: L0, engaged: r3(Math.min(end.thread, zHead + L0 - end.zThr)), spare: r3(end.floor - zHead - L0) };
|
|
777
|
+
else if (fx.printed) none = `no whole millimetre from ${mm2(lo)} to ${mm2(hi)} mm is a length for the printed bolt: ${mm2(grip)} mm under its head (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}) leaves ${mm2(hi - lo)} mm between ${mm2(need)} mm in the nut and ${mm2(FASTEN.floor.value)} mm kept off the slot's floor. A part of another thickness, or a washer under the head`;
|
|
775
778
|
else none = `no ${fx.thread} ${form} screw is sold from ${mm2(lo)} to ${mm2(hi)} mm long, what ${mm2(grip)} mm under its head (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}) leaves: ${mm2(need)} mm in the nut and ${mm2(FASTEN.floor.value)} mm kept off the slot's floor (${(sold.filter((l) => l < lo - EPS).at(-1) ?? null) != null ? `${fx.thread}x${sold.filter((l) => l < lo - EPS).at(-1)} engages too little, ` : ''}${sold.find((l) => l > hi + EPS) != null ? `${fx.thread}x${sold.find((l) => l > hi + EPS)} reaches the floor` : 'none is that long'}). A part of another thickness, or a washer under the head`;
|
|
776
779
|
} else if (end.motor && form !== 'set') { // the longest sold length that stops short of the motor's thread's end, as motor.mount chooses
|
|
777
780
|
const sold = fx.figures.lengths?.value || [], room = end.depth - (end.motor.reach ? 0 : tipRoom), L0 = [...sold].reverse().find((l) => l > grip + EPS && l - grip <= room + (end.motor.reach ? READ : EPS)); // (a maker's reach is the limit itself: no room kept past it, the mesh's grid allowed)
|
|
@@ -801,7 +804,7 @@ export function fastenOf(s, worlds, opts = {}) {
|
|
|
801
804
|
const lenValues = { length: L, grip: r3(grip), into: r3(inEnd) }, under = `${mm2(grip)} mm under its head${washer ? ' (its washer with it)' : ''}`;
|
|
802
805
|
const wouldDo = pick && pick.length !== L ? `${pick.name} would do` : null;
|
|
803
806
|
if (given == null) {
|
|
804
|
-
if (pick && end.slot) say('fasten.length', 'pass', `${pick.name} chosen, the shortest sold that fits: ${under} (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}), ${mm2(pick.engaged)} mm into its nut, its tip ${mm2(zTip - end.mouth)} mm into the slot and ${mm2(pick.spare)} mm short of its floor`, { ...lenValues, floor: r3(pick.spare) });
|
|
807
|
+
if (pick && end.slot) say('fasten.length', 'pass', `${pick.name} chosen, the shortest ${fx.printed ? 'that fits (a printed bolt is printed to any whole millimetre)' : 'sold that fits'}: ${under} (${end.slot.part}${washer ? ', the washer' : ''} and ${lipSays(end.slot)}), ${mm2(pick.engaged)} mm into its nut, its tip ${mm2(zTip - end.mouth)} mm into the slot and ${mm2(pick.spare)} mm short of its floor`, { ...lenValues, floor: r3(pick.spare) });
|
|
805
808
|
else if (pick) say('fasten.length', 'pass', `${pick.name} chosen, the ${end.motor ? (end.motor.reach ? 'longest sold that goes no further than its maker allows' : 'longest sold that stops short of the end of the thread') : fx.printed ? 'shortest that fits (a printed bolt is printed to any whole millimetre)' : 'shortest sold that fits'}: ${under} and ${mm2(pick.engaged)} mm into ${x.into}${end.kind === 'nut' ? '\'s nut' : ''}${pick.spare != null ? `, ${mm2(pick.spare)} mm short of bottoming out` : ''}`, lenValues);
|
|
806
809
|
else if (none) say('fasten.length', 'fail', `no length chosen: ${none}`, lenValues);
|
|
807
810
|
else if (form !== 'set') say('fasten.length', 'info', `no length chosen until the far end is one a screw holds in: ${model.name} is drawn`, lenValues);
|
|
@@ -872,14 +875,22 @@ export function fastenOf(s, worlds, opts = {}) {
|
|
|
872
875
|
if (!st) say('fasten.seat', 'pass', `${where}${seatMat.name ? ` (no strength is known for ${seatMat.name}, so the pressure under it is not checked)` : ''}`, values);
|
|
873
876
|
else {
|
|
874
877
|
const D2 = st.head === 'hex' ? head.across * Math.cos(Math.PI / 6) : head.across, area = (d) => (Math.PI / 4) * (d * d - (2 * boreR) ** 2), bare = area(D2), onWasher = st.washer ? area(st.washer.diameter) : null, mine = washer ? onWasher : bare;
|
|
875
|
-
const takes = st.limit * mine, K = DEFAULTS.nut_factor.value, torqueOf = (N) => (K * fx.major * N) / 1000, v2 = { ...values, area: +mine.toFixed(2), limit: st.limit, force: +takes.toFixed(1), torque: +torqueOf(takes).toFixed(3) };
|
|
878
|
+
const takes = st.limit * mine, K = DEFAULTS.nut_factor.value, torqueOf = (N) => (K * fx.major * N) / 1000, v2 = { ...values, area: +mine.toFixed(2), limit: st.limit, force: +takes.toFixed(1), ...(fx.printed ? {} : { torque: +torqueOf(takes).toFixed(3) }) }; // (a printed bolt: no tightening torque)
|
|
876
879
|
if (!fx.printed) { sc.most = +torqueOf(takes).toFixed(2); sc.seatForce = takes; } // (a printed bolt is done up by hand: no torque to tighten to)
|
|
877
880
|
if (torque == null && fx.printed) say('fasten.seat', 'pass', `${where}; on ${st.material} (${mm(st.limit)} MPa) its ${mm(+mine.toFixed(1))} mm² takes ${mm(+takes.toFixed(0))} N. A printed bolt is done up by hand, with no torque to tighten to`, v2);
|
|
878
881
|
else if (torque == null) say('fasten.seat', 'pass', `${where}; on ${st.material} (${mm(st.limit)} MPa) its ${mm(+mine.toFixed(1))} mm² takes ${mm(+takes.toFixed(0))} N, a tightening of ${mm(+torqueOf(takes).toFixed(2))} N m${!washer && onWasher && sunk <= 0.01 ? `: the ${fx.thread} washer would raise that to ${mm(+(st.limit * onWasher).toFixed(0))} N (${mm(+torqueOf(st.limit * onWasher).toFixed(2))} N m)` : ''}`, v2);
|
|
879
882
|
else {
|
|
880
883
|
const p = st.force / mine, within = p <= st.limit + 1e-9, pw = onWasher ? st.force / onWasher : null;
|
|
881
|
-
|
|
882
|
-
|
|
884
|
+
// A printed bolt turned to a torque by hand: the clamp is T = K d F with steel's nut factor, an estimate for a
|
|
885
|
+
// plastic thread, and held against what the bolt itself breaks at, since a printed bolt breaks long before a seat gives
|
|
886
|
+
const turned = fx.printed ? `turned by hand to ${mm(torque)} N m, it clamps with about ${mm(st.force)} N (T = K d F, fixings.nut_factor ${mm(K)} for steel threads: an estimate for a printed one)` : null;
|
|
887
|
+
if (fx.printed) {
|
|
888
|
+
const bolt = F.printedBoltModel(fx, { length: L, head: form, material, nut: boltMate(sc) }), want = DEFAULTS.load_margin.value, ok = st.force * want <= bolt.breaking + 1e-9, safe = Math.floor(torqueOf(bolt.breaking / want) * 100 + 1e-9) / 100; // (down to the hundredth: rounded up, the most named would fail its own check)
|
|
889
|
+
say('fasten.torque', ok ? 'pass' : st.force <= bolt.breaking ? 'warn' : 'fail', `${turned}: ${ok ? `${mm(+(bolt.breaking / st.force).toFixed(2))} times under the ${mm(bolt.breaking)} N it breaks at (${bolt.governs})` : `${st.force <= bolt.breaking ? `under the ${mm(bolt.breaking)} N it breaks at (${bolt.governs}), but not ${mm(want)} times (fixings.load_margin)` : `more than the ${mm(bolt.breaking)} N it breaks at (${bolt.governs}): turning it that far breaks it`}. Turn it to ${mm(safe)} N m at most, or snug by hand with no torque given`}`,
|
|
890
|
+
{ torque, force: st.force, breaking: bolt.breaking, margin: +(bolt.breaking / st.force).toFixed(2), most: safe });
|
|
891
|
+
}
|
|
892
|
+
if (within) say('fasten.seat', 'pass', `${where}; ${turned ?? `at ${mm(torque)} N m the screw clamps with ${mm(st.force)} N`}, ${mm(+p.toFixed(1))} MPa under the ${washer ? 'washer' : 'head'} on ${st.material}, whose strength is ${mm(st.limit)} MPa`, { ...v2, pressure: +p.toFixed(1) });
|
|
893
|
+
else say('fasten.seat', 'fail', `${turned ?? `at ${mm(torque)} N m the screw clamps with ${mm(st.force)} N`}: ${mm(+p.toFixed(1))} MPa under the ${washer ? 'washer' : 'head'} on ${st.material}, whose strength is ${mm(st.limit)} MPa. ${!washer && pw != null && pw <= st.limit && sunk <= 0.01 ? `The ${fx.thread} washer, ${mm(st.washer.diameter)} mm across, brings it to ${mm(+pw.toFixed(1))} MPa, within: give "washer": true` : `The seat takes ${mm(+takes.toFixed(0))} N (${mm(+torqueOf(takes).toFixed(2))} N m): ${fx.printed ? 'turn it no further than that' : 'tighten to that'}, or spread the load wider`}`, { ...v2, pressure: +p.toFixed(1), ...(pw != null ? { washer: +pw.toFixed(1) } : {}) });
|
|
883
894
|
}
|
|
884
895
|
}
|
|
885
896
|
}
|
|
@@ -920,7 +931,7 @@ export function fastenOf(s, worlds, opts = {}) {
|
|
|
920
931
|
for (const h of hardware.filter((o) => o.fasten === k)) names.set(h.name, (names.get(h.name) ?? 0) + 1);
|
|
921
932
|
// the screws' lines carry the key that turns them and how tight: the torque given, or the most the seat under the head takes
|
|
922
933
|
const keys = [...new Set(rel.screws.map((sc) => sc.tool).filter(Boolean))], most = rel.screws.map((sc) => sc.most).filter((t) => t != null);
|
|
923
|
-
const tighten = torque != null ? { torque, given: true } : most.length ? { torque: Math.min(...most), given: false } : null;
|
|
934
|
+
const tighten = torque != null ? { torque, given: true, ...(fx.printed ? { hand: true } : {}) } : most.length ? { torque: Math.min(...most), given: false } : null;
|
|
924
935
|
const lines = [...names].map(([fastener, n]) => ({ fastener, count: n, ...(rel.screws.some((sc) => sc.model?.name === fastener) ? { ...(keys.length ? { key: keys.join(' or ') } : {}), ...(tighten ? { tighten } : {}) } : {}) }));
|
|
925
936
|
through.forEach((t, j) => fits.push({ a: t, b: slotAt ? slotAt.item : x.into, fastens: true, silent: true, fasten: k, note: x.note || `${t} fastened to ${x.into}`, ...(j === 0 && lines[0] ? lines[0] : {}) }));
|
|
926
937
|
if (!through.length && lines[0]) fits.push({ a: x.into, b: x.into, silent: true, fasten: k, note: label, ...lines[0] });
|
|
@@ -1026,7 +1037,7 @@ export function hardwarePart(h, hostWorld) {
|
|
|
1026
1037
|
hardware: { kind: h.kind, name: h.name, fasten: h.fasten, screw: h.screw, thread: h.thread, grams: h.grams, from: h.label, length: h.length, head: h.head, ...(h.printed ? { printed: true } : {}) }, moves: h.hostItem, with: h.with, lift, allow: h.allow };
|
|
1027
1038
|
}
|
|
1028
1039
|
|
|
1029
|
-
const CODES = ['fasten.holes', 'fasten.slot', 'fasten.clearance', 'fasten.end', 'fasten.length', 'fasten.engagement', 'fasten.seat', 'fasten.access'];
|
|
1040
|
+
const CODES = ['fasten.holes', 'fasten.slot', 'fasten.clearance', 'fasten.end', 'fasten.length', 'fasten.engagement', 'fasten.seat', 'fasten.torque', 'fasten.access'];
|
|
1030
1041
|
// fasten.access for one screw, with the order of assembly: a part over the head that goes on later is no trouble
|
|
1031
1042
|
function accessSays(sc, rel, order, numbered = null) {
|
|
1032
1043
|
const acc = sc.access, t = acc.tool, values = { key: t.size, radius: t.radius, reach: t.reach };
|
package/lib/order.mjs
CHANGED
|
@@ -238,7 +238,7 @@ export function assemblyOrder(s) {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
/** One fastening of a step as the order and the build page say it: the fit, its screws by count and name, the key and how tight. */
|
|
241
|
-
export const fastenerText = (f) => `${f.fit}${f.fastener ? ` (${f.count != null ? `${f.count} × ` : ''}${f.fastener})` : ''}${f.key ? ` with ${/^[aeiou8]/i.test(f.key) ? 'an' : 'a'} ${f.key}` : ''}${f.tighten ? `, ${f.tighten.given ? `to ${f.tighten.torque} N m` : f.tighten.load ? `to ${f.tighten.torque} N m (what the joint's load leaves the thread)` : `to ${f.tighten.torque} N m at most (what the seat takes)`}` : ''}`;
|
|
241
|
+
export const fastenerText = (f) => `${f.fit}${f.fastener ? ` (${f.count != null ? `${f.count} × ` : ''}${f.fastener})` : ''}${f.key ? ` with ${/^[aeiou8]/i.test(f.key) ? 'an' : 'a'} ${f.key}` : ''}${f.tighten ? `, ${f.tighten.hand ? `to ${f.tighten.torque} N m and no further (a printed bolt, turned by hand, not tightened)` : f.tighten.given ? `to ${f.tighten.torque} N m` : f.tighten.load ? `to ${f.tighten.torque} N m (what the joint's load leaves the thread)` : `to ${f.tighten.torque} N m at most (what the seat takes)`}` : ''}`;
|
|
242
242
|
|
|
243
243
|
// Cached by what the parts are and where they are, with everything else that changes the answer (a motor's screw
|
|
244
244
|
// names the tool its step gives)
|
package/lib/pins.mjs
CHANGED
|
@@ -70,7 +70,8 @@ export function pinFit(x, s, f) {
|
|
|
70
70
|
const holes = segs.filter((g) => g.hole), size = (g) => (g.a.loop?.shape === 'round' && g.a.loop.d != null ? Math.min(g.a.loop.d, g.b.loop?.d ?? Infinity) : 2 * Math.min(g.a.free, g.b.free));
|
|
71
71
|
return { lo: segs[0].z0, hi: segs.at(-1).z1, segs, hole: holes.length ? Math.min(...holes.map(size)) : null, solidAt: segs.find((g) => g.solid) ?? null };
|
|
72
72
|
};
|
|
73
|
-
// The pins' places: round holes in a about the pin's hole
|
|
73
|
+
// The pins' places: round holes in a about the pin's hole (a teardrop lying on its side is one: holesIn leaves its
|
|
74
|
+
// roof out of the round), on an axis that goes on into b
|
|
74
75
|
const axes = [];
|
|
75
76
|
for (const q of A) for (const h of holesIn(q)) {
|
|
76
77
|
if (Math.abs(h.d - m0.hole.diameter) > LOOK && !wanted.some((w) => Math.abs(h.d - w.diameter) <= LOOK)) continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.70",
|
|
4
4
|
"description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@rulecad/model-link": "^0.3.2",
|
|
66
66
|
"@rulecad/versions": "^0.1.6",
|
|
67
67
|
"@rulecad/shapes": "^0.4.6",
|
|
68
|
-
"@rulecad/rules": "^0.3.
|
|
68
|
+
"@rulecad/rules": "^0.3.20",
|
|
69
69
|
"@jscad/modeling": "^2.12.0",
|
|
70
70
|
"three": "^0.186.1",
|
|
71
71
|
"@rulecad/fea": "^0.2.11",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"@rulecad/flexures": "^0.5.4",
|
|
74
74
|
"@rulecad/gears": "^0.3.4",
|
|
75
75
|
"@rulecad/motors": "^0.1.6",
|
|
76
|
-
"@rulecad/fixings": "^0.1.
|
|
76
|
+
"@rulecad/fixings": "^0.1.7",
|
|
77
77
|
"@rulecad/robots": "^0.1.3",
|
|
78
|
-
"@rulecad/frames": "^0.1.
|
|
78
|
+
"@rulecad/frames": "^0.1.12"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
"nut": { "anyOf": [{ "type": "boolean" }, { "type": "string" }], "description": "What holds the screw where the part it ends in does not: true or hex, square, lock. It sits on that part's far face, or in a nut's seat drawn there. Into a beam's slot, the slot nut's kind: slide-in, drop-in, roll-in, hammer, square or t-bolt (left out, the strongest made for the slot). A slide-in or square nut enters only from an open end of the slot (frame.nut, frame.preload)" },
|
|
175
175
|
"washer": { "type": "boolean", "description": "A plain washer under the head" },
|
|
176
176
|
"length": { "$ref": "#/$defs/expr", "description": "The screw's length in mm, where the name gives none: checked for reaching, bottoming out and standing proud" },
|
|
177
|
-
"torque": { "$ref": "#/$defs/expr", "description": "The tightening torque, N m: the pressure under the head is then held against the material it sits on (fasten.seat)" },
|
|
177
|
+
"torque": { "$ref": "#/$defs/expr", "description": "The tightening torque, N m: the pressure under the head is then held against the material it sits on (fasten.seat); for a printed bolt, the turn by hand, held against what the bolt breaks at (fasten.torque)" },
|
|
178
178
|
"note": { "type": "string" }
|
|
179
179
|
}
|
|
180
180
|
},
|