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.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:

FileFreeCADBlender
STEPadjustYtoZ ondoes not read STEP
STLadjustYtoZ onadjustYtoZ on
PLYadjustYtoZ onadjustYtoZ on
OBJadjustYtoZ onadjustYtoZ 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. 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, saveShapeSvgAndReturn and svgCreate 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 or saveShapeDxf is given a unit with acadVersion AC1015, the default; the older AC1009 (R12) has no place for it, so a unit given 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.