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
| For | Format | Function |
|---|---|---|
| Another CAD program, exactly | STEP | bitbybit.occt.io.saveShapeSTEP |
| An assembly with names and colours | STEP | the assembly functions |
| 3D printing | STL | bitbybit.occt.io.saveShapeStl |
| Other mesh tools | OBJ, PLY | bitbybit.occt.io.saveShapeObj, saveShapePly |
| The web, AR and game engines | GLB | bitbybit.babylon.io.exportGLB |
| OpenCascade itself | BREP | bitbybit.occt.io.saveShapeBrep |
| Laser cutting and drawings | DXF, SVG | DXF drawings, bitbybit.occt.io.svgCreate, saveShapeDxf, 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, so the file stands in the other program as the model stands on your screen. That holds for every script made on bitbybit.dev today, and in an app on the npm packages that sets conventions: 1. A script saved before scripts followed the engine keeps its earlier behaviour until it is updated; coordinate systems says what that was and how to update it.
Which setting a program wants depends on how it reads the format. These are checked against FreeCAD 1.1 and Blender 5.2 with their default import settings, for a left-handed BabylonJS scene, a right-handed one, ThreeJS and PlayCanvas:
| File | FreeCAD | Blender |
|---|---|---|
| STEP | adjustYtoZ on | does not read STEP |
| STL | adjustYtoZ on | adjustYtoZ on |
| PLY | adjustYtoZ on | adjustYtoZ on |
| OBJ | adjustYtoZ on | adjustYtoZ off, as Blender takes an OBJ file to have Y up |
With the setting a program wants, its front view shows what a camera in front of your model shows: upright, unmirrored, the same way round. The one exception is an OBJ for Blender from a left-handed BabylonJS scene, which Blender shows from behind, as BabylonJS itself shows a glTF model.
Files made in those programs come in the same way. A STEP, IGES or STL file from FreeCAD, or an STL from Blender, loads with adjustZtoY on and stands on your screen as it stood in the program that made it.
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.
saveShapeSTEPandsaveShapeSTEPAndReturnscale a shape built in anotherunitto them; theunitis millimetres when left out. - GLB is in metres, glTF's own unit, when
bitbybit.babylon.io.exportGLBis given theunitthe scene is modelled in; left out, the numbers are written as they are.bitbybit.occt.assembly.manager.exportDocumentToGltftakes the assembly'sunitthe same way. - SVG from
saveShapeSvg,saveShapeSvgAndReturnandsvgCreatestates its true width and height when given the shape'sunit; left out, the drawing has only a view box. - DXF states its unit in the header when
dxfCreateorsaveShapeDxfis given aunitwithacadVersionAC1015, the default; the older AC1009 (R12) has no place for it, so aunitgiven with AC1009 is refused with an error.
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.