Skip to main content

What a script runs in

A TypeScript script, and the code Blockly generates from its blocks, runs inside the editor's page, in the same browser tab. It does not run in the page as an ordinary web page script would: it gets the platform's own objects and nothing of the page around it.

What a script can use​

NameWhat it is
bitbybitthe whole API: bitbybit.occt, bitbybit.draw, bitbybit.point and the rest
Bitthe option classes and types: Bit.Inputs (such as new Bit.Inputs.OCCT.BoxDto()), Bit.Models, Bit.Advanced and Bit.Things
BABYLONthe BabylonJS engine, to build on the scene the editor shows
BABYLON.GUIBabylonJS's 2D and 3D interface controls: buttons, sliders, text over the view

IntelliSense knows all four, and so does the type check that marks errors.

What it cannot use​

window, document and alert are undefined inside a script. A script cannot change the editor's page, and is not meant to: it should draw into the 3D view and talk to the person through BabylonJS's GUI and the console. To show text or controls over the model, use BABYLON.GUI; to keep labels on points of the model, use bitbybit.tag.

Await at the top​

A script can await at its top level, outside any function:

const box = await bitbybit.occt.shapes.solid.createBox({ width: 4, length: 4, height: 4, center: [0, 0, 0] });
await bitbybit.draw.drawAnyAsync({ entity: box });

The console​

console.log, console.info, console.warn and console.error write to the console panel under the editor, as well as to the browser's own. Text appears as it is, an error as its message, and anything else as JSON. The console keeps the last 500 lines of a run, each up to 2,000 characters, and folds a line repeated many times into one with a count.

How a run starts and ends​

  • Each run starts fresh. Run The Code clears the scene of the run before: its shapes, camera, lights, GUI, and the intervals, key listeners and render functions it registered through the API. A plain setInterval of your own is not cleared; prefer bitbybit.time.registerRenderFunction or Blockly's time blocks.
  • There is no time limit and no stop button. A run ends when its code finishes. A loop that never ends keeps the tab busy; reload the page to stop it, after saving your script.
  • An error stops the run and is written to the console as its message. In a script of several files, a mistake in the code itself, such as a missing bracket, is reported with its file and line before anything runs. The type check marks most mistakes before you press run: IntelliSense, hovers and errors.

Files and imports​

A script of several files is put together before it runs, starting from main.ts. Files import each other by relative path, such as ./parts/bracket, and a .json file can be imported for its data. Packages from npm cannot be imported: everything a script needs is already on bitbybit, Bit and BABYLON. Write against the npm packages in your own app when you need more; npm packages shows how.

Verified against the product in October 2026