Skip to main content

Getting a model out

What a script makes can leave Bitbybit as a file.

Without code, More > Export model in the coding editors downloads what the script drew as GLB or STL, or a picture of the 3D view; the 3D view describes it. That is the quickest way, and it takes the drawn triangles.

With code, a script exports what it chooses, at the precision and in the format it chooses, including exact CAD formats such as STEP. Each function below is the same in every editor; in Rete and Blockly you find it by its path, under occt > io or babylon > io.

Which format​

ForFormatFunction
Another CAD program, exactlySTEPbitbybit.occt.io.saveShapeSTEP
An assembly with names and coloursSTEPthe assembly functions
3D printingSTLbitbybit.occt.io.saveShapeStl
Other mesh toolsOBJ, PLYbitbybit.occt.io.saveShapeObj, saveShapePly
The web, AR and game enginesGLBbitbybit.babylon.io.exportGLB
OpenCascade itselfBREPbitbybit.occt.io.saveShapeBrep
Laser cutting and drawingsDXF, SVGDXF drawings, bitbybit.occt.io.saveShapeSvg

STEP, BREP and IGES keep the exact geometry. STL, OBJ, PLY and GLB keep triangles, divided as finely as their precision asks.

Download or keep​

Each save function starts a download in the browser. Its ...AndReturn twin, such as saveShapeSTEPAndReturn, gives the file's content back to the script instead, to upload, measure or pass on:

const box = await bitbybit.occt.shapes.solid.createBox({ width: 40, length: 30, height: 10, center: [0, 5, 0] });
await bitbybit.occt.io.saveShapeSTEP({ shape: box, fileName: "box.step", adjustYtoZ: false, tryDownload: true });
const stl = await bitbybit.occt.io.saveShapeStlAndReturn({ shape: box, fileName: "box.stl", precision: 0.01, adjustYtoZ: false, binary: true });

A download from a script runs every time the script runs, which in Rete is every change. Put the save last, and keep its tryDownload off while you work: turn it on when you want the file.

Which way up​

CAD programs usually treat Z as up, where Bitbybit treats Y as up. adjustYtoZ on the save functions turns the model for them, but it mirrors the part as it does; to keep a part as it is, turn it a quarter turn about X with bitbybit.occt.transforms.rotate before saving instead.

Units​

A model's numbers carry no unit of their own, but a file says what its lengths mean, and a program opening it reads them that way. Tell the save functions the unit the model is built in, and the file opens at its true size:

  • STEP is always written in millimetres. saveShapeSTEP and saveShapeSTEPAndReturn scale a shape built in another unit to them; the unit is millimetres when left out.
  • GLB is in metres, glTF's own unit, when bitbybit.babylon.io.exportGLB is given the unit the scene is modelled in; left out, the numbers are written as they are. bitbybit.occt.assembly.manager.exportDocumentToGltf takes the assembly's unit the same way.
  • SVG from saveShapeSvg and saveShapeSvgAndReturn states its true width and height when given the shape's unit; left out, the drawing has only a view box.
  • DXF states its unit in the header when dxfCreate writes acadVersion AC1015 with a unit; the older AC1009 (R12) has no place for it.

Reading a file goes the other way: STEP and IGES arrive in the unit you ask for.

A picture​

More > Export model > Picture of the 3D view (PNG) saves the view as it is. From code, bitbybit.babylon.tools.createScreenshotAndDownload does the same, at a size and through a camera you choose.

From the Designer and CAD Cloud​

The Designer exports STEP, GLB, STL and BREP from its menu, without code. CAD Cloud returns STEP, glTF and mesh files from a server.