| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.FeatureStudioManager = void 0; | ||
| exports.loadText = loadText; | ||
| const node_fs_1 = require("node:fs"); | ||
| class FeatureStudioManager { | ||
| client; | ||
| constructor(client) { | ||
| this.client = client; | ||
| } | ||
| async create(documentId, workspaceId, name) { | ||
| return this.client.post(`/api/v6/featurestudios/d/${documentId}/w/${workspaceId}`, { name }); | ||
| } | ||
| async getContents(documentId, workspaceId, elementId) { | ||
| return this.client.get(`/api/v6/featurestudios/d/${documentId}/w/${workspaceId}/e/${elementId}`); | ||
| } | ||
| async setContents(documentId, workspaceId, elementId, contents) { | ||
| return this.client.post(`/api/v6/featurestudios/d/${documentId}/w/${workspaceId}/e/${elementId}`, { contents }); | ||
| } | ||
| async getSpecs(documentId, workspaceId, elementId) { | ||
| return this.client.get(`/api/v6/featurestudios/d/${documentId}/w/${workspaceId}/e/${elementId}/featurespecs`); | ||
| } | ||
| } | ||
| exports.FeatureStudioManager = FeatureStudioManager; | ||
| function loadText(inline, file) { | ||
| const raw = file ? (0, node_fs_1.readFileSync)(file, "utf8") : inline; | ||
| if (!raw) | ||
| throw new Error("Expected text via --contents or --contents-file"); | ||
| return raw; | ||
| } |
@@ -7,4 +7,7 @@ "use strict"; | ||
| exports.buildCircleAxisSketch = buildCircleAxisSketch; | ||
| exports.buildCandyCanePathSketch = buildCandyCanePathSketch; | ||
| exports.buildExtrude = buildExtrude; | ||
| exports.buildRevolve = buildRevolve; | ||
| exports.buildOffsetPlane = buildOffsetPlane; | ||
| exports.buildSweep = buildSweep; | ||
| exports.buildBooleanUnion = buildBooleanUnion; | ||
@@ -77,4 +80,37 @@ const INCH_TO_METER = 0.0254; | ||
| } | ||
| function sketch(name, sketchPlaneId, entities) { | ||
| function arcEntity(id, center, radius, startAngle, endAngle) { | ||
| if (radius <= 0) | ||
| throw new Error("Arc radius must be positive."); | ||
| return { | ||
| btType: "BTMSketchCurveSegment-155", | ||
| entityId: id, | ||
| startPointId: `${id}.start`, | ||
| endPointId: `${id}.end`, | ||
| centerId: `${id}.center`, | ||
| startParam: (startAngle * Math.PI) / 180, | ||
| endParam: (endAngle * Math.PI) / 180, | ||
| geometry: { | ||
| btType: "BTCurveGeometryCircle-115", | ||
| radius: toMeters(radius), | ||
| xCenter: toMeters(center[0]), | ||
| yCenter: toMeters(center[1]), | ||
| xDir: 1, | ||
| yDir: 0, | ||
| clockwise: false, | ||
| }, | ||
| isConstruction: false, | ||
| }; | ||
| } | ||
| function sketchPlaneParameter(sketchPlaneId, featureId) { | ||
| if (featureId) { | ||
| return pQuery("sketchPlane", `query = qCreatedBy(makeId("${featureId}"), EntityType.FACE);`, featureId); | ||
| } | ||
| return { | ||
| btType: "BTMParameterQueryList-148", | ||
| queries: [{ btType: "BTMIndividualQuery-138", deterministicIds: [sketchPlaneId] }], | ||
| parameterId: "sketchPlane", | ||
| }; | ||
| } | ||
| function sketch(name, sketchPlaneId, entities, featureId) { | ||
| return { | ||
| feature: { | ||
@@ -85,9 +121,3 @@ btType: "BTMSketch-151", | ||
| suppressed: false, | ||
| parameters: [ | ||
| { | ||
| btType: "BTMParameterQueryList-148", | ||
| queries: [{ btType: "BTMIndividualQuery-138", deterministicIds: [sketchPlaneId] }], | ||
| parameterId: "sketchPlane", | ||
| }, | ||
| ], | ||
| parameters: [sketchPlaneParameter(sketchPlaneId, featureId)], | ||
| entities, | ||
@@ -147,2 +177,16 @@ constraints: [], | ||
| } | ||
| function pDeterministicQuery(parameterId, deterministicIds) { | ||
| return { | ||
| btType: "BTMParameterQueryList-148", | ||
| queries: [ | ||
| { | ||
| btType: "BTMIndividualQuery-138", | ||
| deterministicIds, | ||
| }, | ||
| ], | ||
| parameterId, | ||
| parameterName: "", | ||
| libraryRelationType: "NONE", | ||
| }; | ||
| } | ||
| function sketchRegion(parameterId, sketchFeatureId) { | ||
@@ -166,4 +210,7 @@ return { | ||
| } | ||
| function sketchEdges(parameterId, sketchFeatureId) { | ||
| return pQuery(parameterId, `query = qCreatedBy(makeId("${sketchFeatureId}"), EntityType.EDGE);`, sketchFeatureId); | ||
| } | ||
| function buildCircleSketch(input) { | ||
| return sketch(input.name, planeId(input.plane), [circleEntity("circle.1", input.center, input.radius)]); | ||
| return sketch(input.name, planeId(input.plane), [circleEntity("circle.1", input.center, input.radius)], input.planeFeatureId); | ||
| } | ||
@@ -176,2 +223,23 @@ function buildCircleAxisSketch(input) { | ||
| } | ||
| function buildCandyCanePathSketch(input) { | ||
| const top = input.bottom + input.straightHeight; | ||
| const center = [input.x - input.hookRadius, top]; | ||
| const totalSegments = Math.max(2, Math.floor(input.segments)); | ||
| const arcLength = input.hookRadius * Math.abs((input.hookAngle * Math.PI) / 180); | ||
| const straightShare = input.straightHeight / (input.straightHeight + arcLength); | ||
| const straightSegments = Math.max(1, Math.round(totalSegments * straightShare)); | ||
| const arcSegments = Math.max(1, totalSegments - straightSegments); | ||
| const entities = []; | ||
| for (let index = 0; index < straightSegments; index += 1) { | ||
| const y1 = input.bottom + (input.straightHeight * index) / straightSegments; | ||
| const y2 = input.bottom + (input.straightHeight * (index + 1)) / straightSegments; | ||
| entities.push(lineEntity(`path.stem.${index + 1}`, [input.x, y1], [input.x, y2])); | ||
| } | ||
| for (let index = 0; index < arcSegments; index += 1) { | ||
| const start = (input.hookAngle * index) / arcSegments; | ||
| const end = (input.hookAngle * (index + 1)) / arcSegments; | ||
| entities.push(arcEntity(`path.hook.${index + 1}`, center, input.hookRadius, start, end)); | ||
| } | ||
| return sketch(input.name, planeId(input.plane), entities); | ||
| } | ||
| function buildExtrude(input) { | ||
@@ -218,2 +286,43 @@ return { | ||
| } | ||
| function buildOffsetPlane(input) { | ||
| return { | ||
| btType: "BTFeatureDefinitionCall-1406", | ||
| feature: { | ||
| btType: "BTMFeature-134", | ||
| featureType: "cPlane", | ||
| name: input.name, | ||
| suppressed: false, | ||
| namespace: "", | ||
| parameters: [ | ||
| pEnum("cplaneType", "CPlaneType", "OFFSET"), | ||
| pDeterministicQuery("entities", [planeId(input.basePlane)]), | ||
| pQuantity("offset", input.offset, "in"), | ||
| pBool("oppositeDirection", false), | ||
| ], | ||
| }, | ||
| }; | ||
| } | ||
| function buildSweep(input) { | ||
| return { | ||
| btType: "BTFeatureDefinitionCall-1406", | ||
| feature: { | ||
| btType: "BTMFeature-134", | ||
| featureType: "sweep", | ||
| name: input.name, | ||
| suppressed: false, | ||
| namespace: "", | ||
| parameters: [ | ||
| pEnum("bodyType", "ExtendedToolBodyType", "SOLID"), | ||
| pEnum("operationType", "NewBodyOperationType", input.operationType), | ||
| sketchRegion("profiles", input.profileSketchFeatureId), | ||
| sketchEdges("path", input.pathSketchFeatureId), | ||
| pEnum("profileControl", "ProfileControlMode", "NONE"), | ||
| pBool("hasTwist", false), | ||
| pBool("hasScale", false), | ||
| pBool("trimEnds", true), | ||
| pBool("defaultScope", true), | ||
| ], | ||
| }, | ||
| }; | ||
| } | ||
| function buildBooleanUnion() { | ||
@@ -220,0 +329,0 @@ return { |
+76
-0
@@ -43,2 +43,3 @@ "use strict"; | ||
| const edges_1 = require("./api/edges"); | ||
| const featurestudio_1 = require("./api/featurestudio"); | ||
| const partstudio_1 = require("./api/partstudio"); | ||
@@ -106,2 +107,6 @@ const modeling_1 = require("./builders/modeling"); | ||
| case "delete-element": | ||
| case "create-feature-studio": | ||
| case "get-feature-studio": | ||
| case "set-feature-studio": | ||
| case "get-feature-studio-specs": | ||
| case "add-feature": | ||
@@ -112,4 +117,7 @@ case "update-feature": | ||
| case "sketch-circle-axis": | ||
| case "sketch-candy-cane-path": | ||
| case "extrude": | ||
| case "revolve": | ||
| case "sweep": | ||
| case "offset-plane": | ||
| case "boolean-union": | ||
@@ -245,2 +253,3 @@ case "validate-partstudio": | ||
| const partstudios = new partstudio_1.PartStudioManager(client); | ||
| const featurestudios = new featurestudio_1.FeatureStudioManager(client); | ||
| const edges = new edges_1.EdgeQuery(client); | ||
@@ -338,2 +347,28 @@ switch (parsed.command) { | ||
| } | ||
| case "create-feature-studio": { | ||
| const { doc, ws } = docWorkspace(parsed.options); | ||
| (0, output_1.emit)(await featurestudios.create(doc, ws, requiredOption(parsed.options, "name"))); | ||
| return; | ||
| } | ||
| case "get-feature-studio": { | ||
| const { doc, ws, elem } = dwe(parsed.options); | ||
| (0, output_1.emit)(await featurestudios.getContents(doc, ws, elem)); | ||
| return; | ||
| } | ||
| case "set-feature-studio": { | ||
| const { doc, ws, elem } = dwe(parsed.options); | ||
| try { | ||
| (0, output_1.emit)(await featurestudios.setContents(doc, ws, elem, (0, featurestudio_1.loadText)(stringOption(parsed.options, "contents"), stringOption(parsed.options, "contentsFile")))); | ||
| } | ||
| catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| throw new output_1.CliError(message, null, 2); | ||
| } | ||
| return; | ||
| } | ||
| case "get-feature-studio-specs": { | ||
| const { doc, ws, elem } = dwe(parsed.options); | ||
| (0, output_1.emit)(await featurestudios.getSpecs(doc, ws, elem)); | ||
| return; | ||
| } | ||
| case "add-feature": { | ||
@@ -361,2 +396,3 @@ const { doc, ws, elem } = dwe(parsed.options); | ||
| plane: stringOption(parsed.options, "plane") ?? "Front", | ||
| planeFeatureId: stringOption(parsed.options, "planeFeature"), | ||
| center: parsePointOption(parsed.options, "center"), | ||
@@ -379,2 +415,16 @@ radius: requiredNumberOption(parsed.options, "radius"), | ||
| } | ||
| case "sketch-candy-cane-path": { | ||
| const { doc, ws, elem } = dwe(parsed.options); | ||
| (0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildCandyCanePathSketch)({ | ||
| name: stringOption(parsed.options, "name") ?? "Candy cane centerline", | ||
| plane: stringOption(parsed.options, "plane") ?? "Front", | ||
| x: numberOption(parsed.options, "x", 0), | ||
| bottom: numberOption(parsed.options, "bottom", 0), | ||
| straightHeight: requiredNumberOption(parsed.options, "straightHeight"), | ||
| hookRadius: requiredNumberOption(parsed.options, "hookRadius"), | ||
| hookAngle: numberOption(parsed.options, "hookAngle", 210), | ||
| segments: numberOption(parsed.options, "segments", 24), | ||
| }), !parsed.options.noValidate)); | ||
| return; | ||
| } | ||
| case "extrude": { | ||
@@ -400,2 +450,21 @@ const { doc, ws, elem } = dwe(parsed.options); | ||
| } | ||
| case "sweep": { | ||
| const { doc, ws, elem } = dwe(parsed.options); | ||
| (0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildSweep)({ | ||
| name: stringOption(parsed.options, "name") ?? "Sweep", | ||
| profileSketchFeatureId: requiredOption(parsed.options, "profile"), | ||
| pathSketchFeatureId: requiredOption(parsed.options, "path"), | ||
| operationType: stringOption(parsed.options, "op") ?? "NEW", | ||
| }), !parsed.options.noValidate)); | ||
| return; | ||
| } | ||
| case "offset-plane": { | ||
| const { doc, ws, elem } = dwe(parsed.options); | ||
| (0, output_1.emit)(await addFeatureResult(partstudios, doc, ws, elem, (0, modeling_1.buildOffsetPlane)({ | ||
| name: stringOption(parsed.options, "name") ?? "Offset plane", | ||
| basePlane: stringOption(parsed.options, "basePlane") ?? "Top", | ||
| offset: requiredNumberOption(parsed.options, "offset"), | ||
| }), !parsed.options.noValidate)); | ||
| return; | ||
| } | ||
| case "boolean-union": { | ||
@@ -568,2 +637,6 @@ const { doc, ws, elem } = dwe(parsed.options); | ||
| delete-element | ||
| create-feature-studio | ||
| get-feature-studio | ||
| set-feature-studio | ||
| get-feature-studio-specs | ||
| add-feature | ||
@@ -574,4 +647,7 @@ update-feature | ||
| sketch-circle-axis | ||
| sketch-candy-cane-path | ||
| extrude | ||
| revolve | ||
| sweep | ||
| offset-plane | ||
| boolean-union | ||
@@ -578,0 +654,0 @@ validate-partstudio |
+1
-1
| { | ||
| "name": "onshape", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "description": "Node.js CLI for Onshape CAD automation with the same JSON contract as onshape-cli.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
69426
15.63%12
9.09%1742
14.08%20
5.26%