Skip to main content

Pipeline recipes

Each recipe is a whole script: it uploads a STEP file, runs a short pipeline over it and saves what comes back. The files from Input templates work with all of them. You need what the first tutorial needs: an API key in BITBYBIT_API_KEY, Node.js 22.18 or newer, and a folder with @bitbybit-dev/cad-cloud-sdk installed and "type": "module" in its package.json.

How a pipeline reads your file​

A pipeline takes uploaded files in inputFiles, and a step reads the first of them as $file:0. The recipes write $file:0:text:auto, which reads the file as text and unpacks it first when it is gzip-compressed, so a .step and a .stpz both work. occt.io.loadSTEPorIGES then reads it into a shape; its fileName only tells it the text is STEP. It turns the file's Z up into the Y up the kernel works in, so a plate lying flat in the file has its thickness along Y.

Measure a STEP file​

Every solid's volume, and the size of the box that holds them all: what a quote or a packing estimate starts from.

measure-step.ts
import { readFileSync, writeFileSync } from "node:fs";
import { basename } from "node:path";
import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";

const apiKey = process.env["BITBYBIT_API_KEY"];
if (!apiKey) throw new Error("Set BITBYBIT_API_KEY to your CAD Cloud API key");
const baseUrl = process.env["BITBYBIT_API_URL"];
const client = new BitbybitClient(baseUrl ? { apiKey, baseUrl } : { apiKey });

const file = process.argv[2] ?? "nesting-parts.step";
const uploaded = await client.files.uploadBytes(basename(file), readFileSync(file), "application/octet-stream");

const { downloads } = await client.cad.pipelineAndPoll({
steps: [
{ operation: "occt.io.loadSTEPorIGES", params: { filetext: "$file:0:text:auto", fileName: "part.step" } },
{ operation: "occt.shapes.solid.getSolids", params: { shape: "$ref:0" } },
{ operation: "occt.shapes.solid.getSolidsVolumes", params: { shapes: "$ref:1" } },
{ operation: "occt.operations.boundingBoxSizeOfShape", params: { shape: "$ref:0" } },
{ operation: "json.createEmpty", params: {} },
{ operation: "json.setValueOnProp", params: { json: "$ref:4", property: "volumes", value: "$ref:2" } },
{ operation: "json.setValueOnProp", params: { json: "$ref:5", property: "size", value: "$ref:3" } },
],
inputFiles: [{ fileId: uploaded.fileId, role: "part" }],
outputs: { formats: ["json"] },
});

const result = downloads.find((download) => download.format === "result");
if (result === undefined) throw new Error("The pipeline returned no result");
const measured = (await (await fetch(result.downloadUrl)).json()) as { volumes: number[]; size: number[] };
writeFileSync("measurements.json", `${JSON.stringify(measured, null, 2)}\n`);

measured.volumes.forEach((volume, index) => {
console.log(`solid ${String(index + 1)}: ${volume.toFixed(0)} mm³`);
});
console.log(`all of it fits in ${measured.size.map((side) => side.toFixed(1)).join(" x ")} mm`);

node measure-step.ts nesting-parts.step, on the plates-to-cut template, prints:

solid 1: 25943 mm³
solid 2: 3619 mm³
solid 3: 6400 mm³
all of it fits in 480.0 x 2.0 x 130.0 mm

and saves the same numbers in measurements.json. occt.shapes.solid.getSolids lists the solids in the file, getSolidsVolumes measures each, and occt.operations.boundingBoxSizeOfShape measures the box. The json steps put both into one object, which the pipeline returns as its result because it is the last step.

Read a part's bends​

The thickness of a sheet-metal part and each of its bends: their angle, inner radius and length. Check a part before you send it to the unfold, or fill in the bend table of a drawing.

bend-table.ts
import { readFileSync, writeFileSync } from "node:fs";
import { basename } from "node:path";
import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";

const apiKey = process.env["BITBYBIT_API_KEY"];
if (!apiKey) throw new Error("Set BITBYBIT_API_KEY to your CAD Cloud API key");
const baseUrl = process.env["BITBYBIT_API_URL"];
const client = new BitbybitClient(baseUrl ? { apiKey, baseUrl } : { apiKey });

const file = process.argv[2] ?? "sheet-metal-bracket.step";
const uploaded = await client.files.uploadBytes(basename(file), readFileSync(file), "application/octet-stream");

const { downloads } = await client.cad.pipelineAndPoll({
steps: [
{ operation: "occt.io.loadSTEPorIGES", params: { filetext: "$file:0:text:auto", fileName: "part.step" } },
{ operation: "occtPro.sheetMetal.unfoldSolidReport", params: { shape: "$ref:0", kFactor: 0.44, thicknessOverride: 0 } },
],
inputFiles: [{ fileId: uploaded.fileId, role: "part" }],
outputs: { formats: ["json"] },
});

const result = downloads.find((download) => download.format === "result");
if (result === undefined) throw new Error("The pipeline returned no result");
interface Bend { angleDeg: number; innerRadius: number; bendLineLength: number }
const report = (await (await fetch(result.downloadUrl)).json()) as { ok: boolean; error?: string; thickness: number; kFactor: number; bends: Bend[] };
if (!report.ok) throw new Error(`The part did not unfold: ${report.error ?? ""}`);
writeFileSync("bends.json", `${JSON.stringify(report, null, 2)}\n`);

console.log(`${String(report.thickness)} mm sheet, k-factor ${String(report.kFactor)}`);
console.table(report.bends.map((bend) => ({ angle: bend.angleDeg.toFixed(1), innerRadius: bend.innerRadius.toFixed(2), length: bend.bendLineLength.toFixed(1) })));

node bend-table.ts sheet-metal-bracket.step, on the bent bracket template, prints the thickness, 2 mm sheet, k-factor 0.44, and a table with its one bend: 90 degrees, an inner radius of 3 mm, 20 mm long. bends.json holds the whole report, the same one the unfold routes return: every face with its role, and for each bend its line, its radii and its developed length. A part that does not unfold comes back with ok: false and the reason, which the script throws.

The report reads one part. For a file of several, the solid-report route reports every solid.

Next​