onshape 0.1.3 → 0.2.0
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/README.md +115 -0
- package/dist/api/assemblies.js +60 -0
- package/dist/api/client.js +40 -5
- package/dist/api/configurations.js +18 -0
- package/dist/api/documents.js +7 -0
- package/dist/api/drawings.js +28 -0
- package/dist/api/export.js +109 -0
- package/dist/api/metadata.js +25 -0
- package/dist/api/partstudio.js +37 -0
- package/dist/api/variables.js +29 -0
- package/dist/builders/advanced.js +372 -0
- package/dist/builders/modeling.js +92 -3
- package/dist/cli.js +541 -54
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -42,7 +42,15 @@ const documents_1 = require("./api/documents");
|
|
|
42
42
|
const edges_1 = require("./api/edges");
|
|
43
43
|
const featurestudio_1 = require("./api/featurestudio");
|
|
44
44
|
const partstudio_1 = require("./api/partstudio");
|
|
45
|
+
const export_1 = require("./api/export");
|
|
46
|
+
const variables_1 = require("./api/variables");
|
|
47
|
+
const configurations_1 = require("./api/configurations");
|
|
48
|
+
const assemblies_1 = require("./api/assemblies");
|
|
49
|
+
const drawings_1 = require("./api/drawings");
|
|
50
|
+
const metadata_1 = require("./api/metadata");
|
|
51
|
+
const fsvalue_1 = require("./api/fsvalue");
|
|
45
52
|
const modeling_1 = require("./builders/modeling");
|
|
53
|
+
const advanced_1 = require("./builders/advanced");
|
|
46
54
|
const output_1 = require("./output");
|
|
47
55
|
async function main(argv) {
|
|
48
56
|
try {
|
|
@@ -123,6 +131,47 @@ async function run(argv) {
|
|
|
123
131
|
case "find-circular-edges":
|
|
124
132
|
case "find-edges-by-feature":
|
|
125
133
|
case "mass-properties":
|
|
134
|
+
case "create-sketch":
|
|
135
|
+
case "sketch-rectangle":
|
|
136
|
+
case "sketch-line":
|
|
137
|
+
case "hole":
|
|
138
|
+
case "thicken":
|
|
139
|
+
case "fillet":
|
|
140
|
+
case "chamfer":
|
|
141
|
+
case "shell":
|
|
142
|
+
case "draft":
|
|
143
|
+
case "boolean":
|
|
144
|
+
case "mirror":
|
|
145
|
+
case "linear-pattern":
|
|
146
|
+
case "circular-pattern":
|
|
147
|
+
case "measure":
|
|
148
|
+
case "eval-featurescript":
|
|
149
|
+
case "get-variables":
|
|
150
|
+
case "set-variable":
|
|
151
|
+
case "get-configuration":
|
|
152
|
+
case "encode-configuration":
|
|
153
|
+
case "export-stl":
|
|
154
|
+
case "export":
|
|
155
|
+
case "thumbnail-info":
|
|
156
|
+
case "get-thumbnail":
|
|
157
|
+
case "shaded-view":
|
|
158
|
+
case "get-assembly":
|
|
159
|
+
case "create-assembly":
|
|
160
|
+
case "insert-instance":
|
|
161
|
+
case "get-assembly-features":
|
|
162
|
+
case "assembly-add-feature":
|
|
163
|
+
case "assembly-mate-connector":
|
|
164
|
+
case "assembly-mate":
|
|
165
|
+
case "assembly-group":
|
|
166
|
+
case "get-bom":
|
|
167
|
+
case "assembly-mass-properties":
|
|
168
|
+
case "delete-instance":
|
|
169
|
+
case "transform-instance":
|
|
170
|
+
case "create-drawing":
|
|
171
|
+
case "get-drawing-views":
|
|
172
|
+
case "export-drawing":
|
|
173
|
+
case "get-metadata":
|
|
174
|
+
case "set-metadata":
|
|
126
175
|
await handleReadCommand(parsed);
|
|
127
176
|
return;
|
|
128
177
|
default:
|
|
@@ -249,6 +298,12 @@ async function handleReadCommand(parsed) {
|
|
|
249
298
|
const partstudios = new partstudio_1.PartStudioManager(client);
|
|
250
299
|
const featurestudios = new featurestudio_1.FeatureStudioManager(client);
|
|
251
300
|
const edges = new edges_1.EdgeQuery(client);
|
|
301
|
+
const exports = new export_1.ExportManager(client);
|
|
302
|
+
const variables = new variables_1.VariableManager(client);
|
|
303
|
+
const configurations = new configurations_1.ConfigurationManager(client);
|
|
304
|
+
const assemblies = new assemblies_1.AssemblyManager(client);
|
|
305
|
+
const drawings = new drawings_1.DrawingManager(client);
|
|
306
|
+
const metadata = new metadata_1.MetadataManager(client);
|
|
252
307
|
switch (parsed.command) {
|
|
253
308
|
case "list-documents": {
|
|
254
309
|
const filterMap = { all: undefined, owned: 1, created: 4, shared: 5 };
|
|
@@ -432,12 +487,24 @@ async function handleReadCommand(parsed) {
|
|
|
432
487
|
}
|
|
433
488
|
case "revolve": {
|
|
434
489
|
const { doc, ws, elem } = dwe(parsed.options);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
490
|
+
const axisIds = splitList(stringOption(parsed.options, "axisIds"));
|
|
491
|
+
const axisQuery = stringOption(parsed.options, "axis");
|
|
492
|
+
const name = stringOption(parsed.options, "name") ?? "Revolve";
|
|
493
|
+
const sketchFeatureId = requiredOption(parsed.options, "sketch");
|
|
494
|
+
const angle = numberOption(parsed.options, "angle", 360);
|
|
495
|
+
const operationType = stringOption(parsed.options, "op") ?? "NEW";
|
|
496
|
+
const feature = axisIds.length || axisQuery
|
|
497
|
+
? (0, advanced_1.buildRevolveAxis)({
|
|
498
|
+
name,
|
|
499
|
+
sketchFeatureId,
|
|
500
|
+
axisIds: axisIds.length ? axisIds : undefined,
|
|
501
|
+
axisQuery,
|
|
502
|
+
operationType,
|
|
503
|
+
revolveType: stringOption(parsed.options, "type") ?? "FULL",
|
|
504
|
+
angle,
|
|
505
|
+
})
|
|
506
|
+
: (0, modeling_1.buildRevolve)({ name, sketchFeatureId, angle, operationType });
|
|
507
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, feature, !parsed.options.noValidate));
|
|
441
508
|
return;
|
|
442
509
|
}
|
|
443
510
|
case "sweep": {
|
|
@@ -452,10 +519,14 @@ async function handleReadCommand(parsed) {
|
|
|
452
519
|
}
|
|
453
520
|
case "offset-plane": {
|
|
454
521
|
const { doc, ws, elem } = dwe(parsed.options);
|
|
455
|
-
|
|
522
|
+
const baseIds = splitList(stringOption(parsed.options, "baseIds"));
|
|
523
|
+
const basePlane = stringOption(parsed.options, "basePlane");
|
|
524
|
+
const basePlaneIds = baseIds.length ? baseIds : basePlane ? [(0, modeling_1.planeId)(basePlane)] : undefined;
|
|
525
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildOffsetPlaneSelect)({
|
|
456
526
|
name: stringOption(parsed.options, "name") ?? "Offset plane",
|
|
457
|
-
|
|
458
|
-
|
|
527
|
+
basePlaneIds,
|
|
528
|
+
basePlaneQuery: stringOption(parsed.options, "baseQuery"),
|
|
529
|
+
offset: numberOption(parsed.options, "offset", 1.0),
|
|
459
530
|
}), !parsed.options.noValidate));
|
|
460
531
|
return;
|
|
461
532
|
}
|
|
@@ -500,8 +571,419 @@ async function handleReadCommand(parsed) {
|
|
|
500
571
|
}));
|
|
501
572
|
return;
|
|
502
573
|
}
|
|
574
|
+
// ---- sketching ----
|
|
575
|
+
case "create-sketch": {
|
|
576
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
577
|
+
let entities;
|
|
578
|
+
try {
|
|
579
|
+
const parsedEntities = JSON.parse(requiredOption(parsed.options, "entities"));
|
|
580
|
+
if (!Array.isArray(parsedEntities))
|
|
581
|
+
throw new Error("--entities must be a JSON array");
|
|
582
|
+
entities = parsedEntities;
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
throw new output_1.CliError(error instanceof Error ? error.message : String(error), null, 2);
|
|
586
|
+
}
|
|
587
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildSketchFromEntities)({
|
|
588
|
+
name: stringOption(parsed.options, "name") ?? "Sketch",
|
|
589
|
+
plane: stringOption(parsed.options, "plane") ?? "Front",
|
|
590
|
+
entities,
|
|
591
|
+
}), !parsed.options.noValidate));
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
case "sketch-rectangle": {
|
|
595
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
596
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildRectangleSketch)({
|
|
597
|
+
name: stringOption(parsed.options, "name") ?? "Sketch",
|
|
598
|
+
plane: stringOption(parsed.options, "plane") ?? "Front",
|
|
599
|
+
corner1: parsePointOption(parsed.options, "corner1"),
|
|
600
|
+
corner2: parsePointOption(parsed.options, "corner2"),
|
|
601
|
+
}), !parsed.options.noValidate));
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
case "sketch-line": {
|
|
605
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
606
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildLineSketch)({
|
|
607
|
+
name: stringOption(parsed.options, "name") ?? "Sketch",
|
|
608
|
+
plane: stringOption(parsed.options, "plane") ?? "Front",
|
|
609
|
+
start: parsePointOption(parsed.options, "start"),
|
|
610
|
+
end: parsePointOption(parsed.options, "end"),
|
|
611
|
+
}), !parsed.options.noValidate));
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
// ---- solids / modifiers ----
|
|
615
|
+
case "hole": {
|
|
616
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
617
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildExtrude)({
|
|
618
|
+
name: stringOption(parsed.options, "name") ?? "Hole",
|
|
619
|
+
sketchFeatureId: requiredOption(parsed.options, "sketch"),
|
|
620
|
+
depth: requiredNumberOption(parsed.options, "depth"),
|
|
621
|
+
operationType: "REMOVE",
|
|
622
|
+
depthVariable: stringOption(parsed.options, "depthVar"),
|
|
623
|
+
}), !parsed.options.noValidate));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
case "thicken": {
|
|
627
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
628
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildThicken)({
|
|
629
|
+
name: stringOption(parsed.options, "name") ?? "Thicken",
|
|
630
|
+
sketchFeatureId: requiredOption(parsed.options, "sketch"),
|
|
631
|
+
thickness: requiredNumberOption(parsed.options, "thickness"),
|
|
632
|
+
operationType: stringOption(parsed.options, "op") ?? "NEW",
|
|
633
|
+
}), !parsed.options.noValidate));
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
case "fillet": {
|
|
637
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
638
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildFillet)({
|
|
639
|
+
name: stringOption(parsed.options, "name") ?? "Fillet",
|
|
640
|
+
radius: numberOption(parsed.options, "radius", 0.06),
|
|
641
|
+
filletType: stringOption(parsed.options, "type") ?? "EDGE",
|
|
642
|
+
...selection(parsed.options),
|
|
643
|
+
}), !parsed.options.noValidate));
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
case "chamfer": {
|
|
647
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
648
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildChamfer)({
|
|
649
|
+
name: stringOption(parsed.options, "name") ?? "Chamfer",
|
|
650
|
+
width: numberOption(parsed.options, "width", 0.08),
|
|
651
|
+
chamferType: stringOption(parsed.options, "type") ?? "EQUAL_OFFSETS",
|
|
652
|
+
angle: optionalNumberOption(parsed.options, "angle"),
|
|
653
|
+
...selection(parsed.options),
|
|
654
|
+
}), !parsed.options.noValidate));
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
case "shell": {
|
|
658
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
659
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildShell)({
|
|
660
|
+
name: stringOption(parsed.options, "name") ?? "Shell",
|
|
661
|
+
thickness: numberOption(parsed.options, "thickness", 0.125),
|
|
662
|
+
faceIds: splitList(stringOption(parsed.options, "faces")),
|
|
663
|
+
queryString: stringOption(parsed.options, "query"),
|
|
664
|
+
inward: !parsed.options.outward,
|
|
665
|
+
}), !parsed.options.noValidate));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
case "draft": {
|
|
669
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
670
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildDraft)({
|
|
671
|
+
name: stringOption(parsed.options, "name") ?? "Draft",
|
|
672
|
+
angle: numberOption(parsed.options, "angle", 3.0),
|
|
673
|
+
neutralPlaneQuery: requiredOption(parsed.options, "neutral"),
|
|
674
|
+
faceQuery: requiredOption(parsed.options, "faces"),
|
|
675
|
+
}), !parsed.options.noValidate));
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
// ---- patterns / boolean ----
|
|
679
|
+
case "boolean": {
|
|
680
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
681
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildBoolean)({
|
|
682
|
+
name: stringOption(parsed.options, "name") ?? "Boolean",
|
|
683
|
+
operationType: stringOption(parsed.options, "op") ?? "UNION",
|
|
684
|
+
toolIds: splitList(stringOption(parsed.options, "toolIds")),
|
|
685
|
+
toolsQuery: stringOption(parsed.options, "tools"),
|
|
686
|
+
targetsQuery: stringOption(parsed.options, "targets"),
|
|
687
|
+
keepTools: Boolean(parsed.options.keepTools),
|
|
688
|
+
}), !parsed.options.noValidate));
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
case "mirror": {
|
|
692
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
693
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildMirror)({
|
|
694
|
+
name: stringOption(parsed.options, "name") ?? "Mirror",
|
|
695
|
+
patternType: stringOption(parsed.options, "type") ?? "PART",
|
|
696
|
+
entitiesQuery: requiredOption(parsed.options, "entities"),
|
|
697
|
+
mirrorPlaneIds: splitList(stringOption(parsed.options, "planeIds")),
|
|
698
|
+
mirrorPlaneQuery: stringOption(parsed.options, "planeQuery"),
|
|
699
|
+
}), !parsed.options.noValidate));
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
case "linear-pattern": {
|
|
703
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
704
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildLinearPattern)({
|
|
705
|
+
name: stringOption(parsed.options, "name") ?? "Linear Pattern",
|
|
706
|
+
patternType: stringOption(parsed.options, "type") ?? "PART",
|
|
707
|
+
entitiesQuery: requiredOption(parsed.options, "entities"),
|
|
708
|
+
directionIds: splitList(stringOption(parsed.options, "directionIds")),
|
|
709
|
+
directionQuery: stringOption(parsed.options, "direction"),
|
|
710
|
+
distance: requiredNumberOption(parsed.options, "distance"),
|
|
711
|
+
instanceCount: requiredNumberOption(parsed.options, "count"),
|
|
712
|
+
opposite: Boolean(parsed.options.opposite),
|
|
713
|
+
}), !parsed.options.noValidate));
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
case "circular-pattern": {
|
|
717
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
718
|
+
(0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, advanced_1.buildCircularPattern)({
|
|
719
|
+
name: stringOption(parsed.options, "name") ?? "Circular Pattern",
|
|
720
|
+
patternType: stringOption(parsed.options, "type") ?? "PART",
|
|
721
|
+
entitiesQuery: requiredOption(parsed.options, "entities"),
|
|
722
|
+
axisIds: splitList(stringOption(parsed.options, "axisIds")),
|
|
723
|
+
axisQuery: stringOption(parsed.options, "axis"),
|
|
724
|
+
instanceCount: requiredNumberOption(parsed.options, "count"),
|
|
725
|
+
angle: numberOption(parsed.options, "angle", 360.0),
|
|
726
|
+
equalSpacing: !parsed.options.noEqualSpacing,
|
|
727
|
+
}), !parsed.options.noValidate));
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
// ---- query / measure ----
|
|
731
|
+
case "measure": {
|
|
732
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
733
|
+
(0, output_1.emit)(await partstudios.measure(doc, ws, elem));
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
case "eval-featurescript": {
|
|
737
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
738
|
+
const scriptFile = stringOption(parsed.options, "scriptFile");
|
|
739
|
+
const script = scriptFile ? (0, featurestudio_1.loadText)(undefined, scriptFile) : stringOption(parsed.options, "script") ?? "";
|
|
740
|
+
const resp = (await partstudios.evaluateFeatureScript(doc, ws, elem, script));
|
|
741
|
+
if (parsed.options.raw) {
|
|
742
|
+
(0, output_1.emit)(resp);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const messages = (0, fsvalue_1.featurescriptMessages)(resp);
|
|
746
|
+
if (!isRecord(resp) || resp.result === null || resp.result === undefined) {
|
|
747
|
+
throw new output_1.CliError(String(messages[0]?.message ?? "FeatureScript evaluation failed"), messages, 1);
|
|
748
|
+
}
|
|
749
|
+
const out = { value: (0, fsvalue_1.decodeFsValue)(resp.result) };
|
|
750
|
+
if (resp.console)
|
|
751
|
+
out.console = resp.console;
|
|
752
|
+
if (messages.length)
|
|
753
|
+
out.warnings = messages;
|
|
754
|
+
(0, output_1.emit)(out);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
// ---- variables ----
|
|
758
|
+
case "get-variables": {
|
|
759
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
760
|
+
(0, output_1.emit)(await variables.getVariables(doc, ws, elem));
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
case "set-variable": {
|
|
764
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
765
|
+
(0, output_1.emit)(await variables.setVariable(doc, ws, elem, requiredOption(parsed.options, "name"), requiredOption(parsed.options, "expression"), stringOption(parsed.options, "description")));
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
// ---- configurations ----
|
|
769
|
+
case "get-configuration": {
|
|
770
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
771
|
+
(0, output_1.emit)(await configurations.getConfiguration(doc, ws, elem));
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
case "encode-configuration": {
|
|
775
|
+
const { doc, elem } = dwe(parsed.options);
|
|
776
|
+
const params = loadJsonArray(parsed.options, "params", "paramsFile");
|
|
777
|
+
(0, output_1.emit)(await configurations.encodeConfiguration(doc, elem, params));
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
// ---- export / images ----
|
|
781
|
+
case "export-stl": {
|
|
782
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
783
|
+
const out = requiredOption(parsed.options, "out");
|
|
784
|
+
const written = await exports.exportStl(doc, ws, elem, out, {
|
|
785
|
+
binary: !parsed.options.ascii,
|
|
786
|
+
resolution: stringOption(parsed.options, "resolution") ?? "medium",
|
|
787
|
+
configuration: stringOption(parsed.options, "configuration"),
|
|
788
|
+
});
|
|
789
|
+
(0, output_1.emit)({ written });
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
case "export": {
|
|
793
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
794
|
+
const out = requiredOption(parsed.options, "out");
|
|
795
|
+
const format = stringOption(parsed.options, "format") ?? "STEP";
|
|
796
|
+
const written = await exports.exportTranslation(doc, ws, elem, out, {
|
|
797
|
+
formatName: format,
|
|
798
|
+
elementKind: stringOption(parsed.options, "kind") ?? "partstudios",
|
|
799
|
+
configuration: stringOption(parsed.options, "configuration"),
|
|
800
|
+
});
|
|
801
|
+
(0, output_1.emit)({ written, format });
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
case "thumbnail-info": {
|
|
805
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
806
|
+
(0, output_1.emit)(await exports.thumbnailInfo(doc, ws, elem));
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
case "get-thumbnail": {
|
|
810
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
811
|
+
const out = requiredOption(parsed.options, "out");
|
|
812
|
+
const size = stringOption(parsed.options, "size") ?? "600x340";
|
|
813
|
+
const written = await exports.getThumbnail(doc, ws, elem, out, { size });
|
|
814
|
+
(0, output_1.emit)({ written, size });
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
case "shaded-view": {
|
|
818
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
819
|
+
const out = requiredOption(parsed.options, "out");
|
|
820
|
+
const written = await exports.shadedView(doc, ws, elem, out, {
|
|
821
|
+
elementKind: stringOption(parsed.options, "kind") ?? "partstudios",
|
|
822
|
+
width: numberOption(parsed.options, "width", 600),
|
|
823
|
+
height: numberOption(parsed.options, "height", 340),
|
|
824
|
+
viewMatrix: stringOption(parsed.options, "viewMatrix"),
|
|
825
|
+
showEdges: !parsed.options.noEdges,
|
|
826
|
+
configuration: stringOption(parsed.options, "configuration"),
|
|
827
|
+
});
|
|
828
|
+
(0, output_1.emit)({ written });
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
// ---- assemblies ----
|
|
832
|
+
case "get-assembly": {
|
|
833
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
834
|
+
(0, output_1.emit)(await docs.getAssembly(doc, ws, elem));
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
case "create-assembly": {
|
|
838
|
+
const { doc, ws } = docWorkspace(parsed.options);
|
|
839
|
+
(0, output_1.emit)(await assemblies.createAssembly(doc, ws, requiredOption(parsed.options, "name")));
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
case "insert-instance": {
|
|
843
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
844
|
+
(0, output_1.emit)(await assemblies.insertInstance(doc, ws, elem, {
|
|
845
|
+
sourceDocumentId: stringOption(parsed.options, "srcDoc") ?? doc,
|
|
846
|
+
sourceElementId: requiredOption(parsed.options, "srcElem"),
|
|
847
|
+
partId: stringOption(parsed.options, "part"),
|
|
848
|
+
sourceVersionId: stringOption(parsed.options, "srcVersion"),
|
|
849
|
+
isAssembly: Boolean(parsed.options.isAssembly),
|
|
850
|
+
isWholePartStudio: Boolean(parsed.options.wholeStudio),
|
|
851
|
+
configuration: stringOption(parsed.options, "configuration"),
|
|
852
|
+
}));
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
case "get-assembly-features": {
|
|
856
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
857
|
+
(0, output_1.emit)(await assemblies.getFeatures(doc, ws, elem));
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
case "assembly-add-feature": {
|
|
861
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
862
|
+
(0, output_1.emit)(await addAssemblyFeature(assemblies, doc, ws, elem, requiredJson(parsed.options)));
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
case "assembly-mate-connector": {
|
|
866
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
867
|
+
(0, output_1.emit)(await addAssemblyFeature(assemblies, doc, ws, elem, (0, advanced_1.buildAssemblyMateConnector)({
|
|
868
|
+
name: stringOption(parsed.options, "name") ?? "Mate connector",
|
|
869
|
+
occurrenceId: requiredOption(parsed.options, "occurrence"),
|
|
870
|
+
inferenceType: stringOption(parsed.options, "inference") ?? "CENTROID",
|
|
871
|
+
})));
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
case "assembly-mate": {
|
|
875
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
876
|
+
(0, output_1.emit)(await addAssemblyFeature(assemblies, doc, ws, elem, (0, advanced_1.buildAssemblyMate)({
|
|
877
|
+
name: stringOption(parsed.options, "name") ?? "Mate",
|
|
878
|
+
mateType: stringOption(parsed.options, "type") ?? "FASTENED",
|
|
879
|
+
mateConnectorIds: splitList(requiredOption(parsed.options, "connectors")),
|
|
880
|
+
})));
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
case "assembly-group": {
|
|
884
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
885
|
+
(0, output_1.emit)(await addAssemblyFeature(assemblies, doc, ws, elem, (0, advanced_1.buildAssemblyGroup)({
|
|
886
|
+
name: stringOption(parsed.options, "name") ?? "Group",
|
|
887
|
+
occurrenceIds: splitList(requiredOption(parsed.options, "occurrences")),
|
|
888
|
+
})));
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
case "get-bom": {
|
|
892
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
893
|
+
(0, output_1.emit)(await assemblies.getBom(doc, ws, elem, { multiLevel: Boolean(parsed.options.multiLevel) }));
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
case "assembly-mass-properties": {
|
|
897
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
898
|
+
(0, output_1.emit)(await assemblies.massProperties(doc, ws, elem));
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
case "delete-instance": {
|
|
902
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
903
|
+
(0, output_1.emit)(await assemblies.deleteInstance(doc, ws, elem, requiredOption(parsed.options, "node")));
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
case "transform-instance": {
|
|
907
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
908
|
+
const paths = loadJsonArray(parsed.options, "paths", "pathsFile");
|
|
909
|
+
const transform = loadJsonArray(parsed.options, "transform", "transformFile");
|
|
910
|
+
(0, output_1.emit)(await assemblies.transformOccurrences(doc, ws, elem, paths, transform, { isRelative: !parsed.options.absolute }));
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
// ---- drawings ----
|
|
914
|
+
case "create-drawing": {
|
|
915
|
+
const { doc, ws } = docWorkspace(parsed.options);
|
|
916
|
+
(0, output_1.emit)(await drawings.createDrawing(doc, ws, {
|
|
917
|
+
name: requiredOption(parsed.options, "name"),
|
|
918
|
+
sourceElementId: requiredOption(parsed.options, "srcElem"),
|
|
919
|
+
sourceVersionId: requiredOption(parsed.options, "srcVersion"),
|
|
920
|
+
sourceDocumentId: stringOption(parsed.options, "srcDoc"),
|
|
921
|
+
partId: stringOption(parsed.options, "part"),
|
|
922
|
+
}));
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
case "get-drawing-views": {
|
|
926
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
927
|
+
(0, output_1.emit)(await drawings.getViews(doc, ws, elem));
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
case "export-drawing": {
|
|
931
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
932
|
+
const out = requiredOption(parsed.options, "out");
|
|
933
|
+
const format = stringOption(parsed.options, "format") ?? "PDF";
|
|
934
|
+
const written = await exports.exportTranslation(doc, ws, elem, out, { formatName: format, elementKind: "drawings" });
|
|
935
|
+
(0, output_1.emit)({ written, format });
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
// ---- metadata ----
|
|
939
|
+
case "get-metadata": {
|
|
940
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
941
|
+
const part = stringOption(parsed.options, "part");
|
|
942
|
+
(0, output_1.emit)(part ? await metadata.getPartMetadata(doc, ws, elem, part) : await metadata.getElementMetadata(doc, ws, elem));
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
case "set-metadata": {
|
|
946
|
+
const { doc, ws, elem } = dwe(parsed.options);
|
|
947
|
+
const properties = loadJsonArray(parsed.options, "properties", "propertiesFile");
|
|
948
|
+
(0, output_1.emit)(await metadata.setElementMetadata(doc, ws, elem, properties, stringOption(parsed.options, "part")));
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
503
951
|
}
|
|
504
952
|
}
|
|
953
|
+
function selection(options) {
|
|
954
|
+
return {
|
|
955
|
+
edgeIds: splitList(stringOption(options, "edges")),
|
|
956
|
+
queryString: stringOption(options, "query"),
|
|
957
|
+
featureId: stringOption(options, "feature"),
|
|
958
|
+
selectAll: Boolean(options.all),
|
|
959
|
+
circular: Boolean(options.circular),
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
function splitList(value) {
|
|
963
|
+
if (!value)
|
|
964
|
+
return [];
|
|
965
|
+
return value
|
|
966
|
+
.split(",")
|
|
967
|
+
.map((item) => item.trim())
|
|
968
|
+
.filter((item) => item.length > 0);
|
|
969
|
+
}
|
|
970
|
+
function loadJsonArray(options, inlineKey, fileKey) {
|
|
971
|
+
let parsed;
|
|
972
|
+
try {
|
|
973
|
+
parsed = (0, partstudio_1.loadJson)(stringOption(options, inlineKey), stringOption(options, fileKey));
|
|
974
|
+
}
|
|
975
|
+
catch (error) {
|
|
976
|
+
throw new output_1.CliError(error instanceof Error ? error.message : String(error), null, 2);
|
|
977
|
+
}
|
|
978
|
+
if (!Array.isArray(parsed))
|
|
979
|
+
throw new output_1.CliError(`--${inlineKey} must be a JSON array`, null, 2);
|
|
980
|
+
return parsed;
|
|
981
|
+
}
|
|
982
|
+
async function addAssemblyFeature(assemblies, doc, ws, elem, feature) {
|
|
983
|
+
const response = await assemblies.addFeature(doc, ws, elem, feature);
|
|
984
|
+
const featureId = isRecord(response) && isRecord(response.feature) ? response.feature.featureId ?? null : null;
|
|
985
|
+
return { featureId, response };
|
|
986
|
+
}
|
|
505
987
|
async function addFeatureResult(partstudios, doc, ws, elem, feature, validate) {
|
|
506
988
|
const response = await partstudios.addFeature(doc, ws, elem, feature);
|
|
507
989
|
const featureId = isRecord(response) && isRecord(response.feature) ? response.feature.featureId ?? null : null;
|
|
@@ -597,54 +1079,59 @@ function storeMode(options) {
|
|
|
597
1079
|
throw new output_1.CliError("--store must be one of: auto, file, keychain", null, 2);
|
|
598
1080
|
}
|
|
599
1081
|
function printHelp() {
|
|
600
|
-
console.log(`onshape
|
|
1082
|
+
console.log(`onshape — command-line automation for Onshape CAD
|
|
601
1083
|
|
|
602
1084
|
Usage:
|
|
603
1085
|
onshape <command> [options]
|
|
604
1086
|
|
|
605
|
-
|
|
606
|
-
login
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
list-documents
|
|
610
|
-
|
|
611
|
-
get-
|
|
612
|
-
get-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
create-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
get-feature
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
get-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
1087
|
+
Credentials:
|
|
1088
|
+
login logout config set|show|path|clear
|
|
1089
|
+
|
|
1090
|
+
Documents & discovery:
|
|
1091
|
+
list-documents search-documents get-document get-document-summary
|
|
1092
|
+
create-document delete-document update-document get-elements
|
|
1093
|
+
find-part-studios get-workspaces list-versions create-version
|
|
1094
|
+
get-parts get-features get-feature-specs get-sketch-info
|
|
1095
|
+
get-body-details get-assembly
|
|
1096
|
+
|
|
1097
|
+
Part studio management:
|
|
1098
|
+
create-part-studio delete-feature delete-element
|
|
1099
|
+
add-feature update-feature rollback validate-partstudio
|
|
1100
|
+
|
|
1101
|
+
Sketching:
|
|
1102
|
+
create-sketch sketch-rectangle sketch-circle sketch-line
|
|
1103
|
+
sketch-circle-axis sketch-candy-cane-path
|
|
1104
|
+
|
|
1105
|
+
Solids & modifiers:
|
|
1106
|
+
extrude hole thicken revolve sweep draft fillet chamfer shell
|
|
1107
|
+
|
|
1108
|
+
Patterns & boolean:
|
|
1109
|
+
boolean boolean-union mirror linear-pattern circular-pattern offset-plane
|
|
1110
|
+
|
|
1111
|
+
Geometry / measure:
|
|
1112
|
+
get-edges find-circular-edges find-edges-by-feature measure
|
|
1113
|
+
eval-featurescript mass-properties
|
|
1114
|
+
|
|
1115
|
+
Variables & configurations:
|
|
1116
|
+
get-variables set-variable get-configuration encode-configuration
|
|
1117
|
+
|
|
1118
|
+
Export & images:
|
|
1119
|
+
export-stl export thumbnail-info get-thumbnail shaded-view
|
|
1120
|
+
|
|
1121
|
+
Assemblies:
|
|
1122
|
+
create-assembly insert-instance get-assembly-features assembly-add-feature
|
|
1123
|
+
assembly-mate-connector assembly-mate assembly-group get-bom
|
|
1124
|
+
assembly-mass-properties delete-instance transform-instance
|
|
1125
|
+
|
|
1126
|
+
Drawings:
|
|
1127
|
+
create-drawing get-drawing-views export-drawing
|
|
1128
|
+
|
|
1129
|
+
Feature studios:
|
|
1130
|
+
create-feature-studio get-feature-studio set-feature-studio get-feature-studio-specs
|
|
1131
|
+
|
|
1132
|
+
Metadata:
|
|
1133
|
+
get-metadata set-metadata
|
|
1134
|
+
|
|
1135
|
+
Every command prints {"ok": true, "result": ...} or {"ok": false, "error": ..., "detail": ...}.
|
|
649
1136
|
`);
|
|
650
1137
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onshape",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Node.js CLI for Onshape CAD automation with
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Node.js CLI for Onshape CAD automation — full command parity with onshape-cli (same flags + JSON contract).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"bin": {
|