Skip to main content

A Parametric Cube

Parametric means that a shape follows its parameters: change a number and the geometry is rebuilt from it. In code a parameter is simply a value the rest of the script reads. Here one constant sizes a cube made by OCCT, the CAD kernel behind solids on Bitbybit.

Before you start​

Open an empty TypeScript editor. If this is your first TypeScript script, Hello World shows the basics first.

The steps​

  1. Add this line to main.ts:

    const size = 3;

    One constant holds the parameter; everything that depends on it reads it.

    A cube one number sizes, step 1 in the TypeScript editor: main.ts with the lines this step adds
  2. Type bitbybit.occt.shapes.solid. and IntelliSense lists what the API offers there. Then add these lines to main.ts:

    const cubeOptions = new Bit.Inputs.OCCT.CubeDto();
    cubeOptions.size = size;
    const cube = await bitbybit.occt.shapes.solid.createCube(cubeOptions);

    The API follows its categories: occt, then shapes, then solid. The cube is a solid made by OCCT, the CAD kernel, so it is awaited.

    A cube one number sizes, step 2 in the TypeScript editor: bitbybit.occt.shapes.solid. typed into main.ts and IntelliSense listing what the API offers there, each entry with its description
  3. Add this line to main.ts:

    await bitbybit.draw.drawAnyAsync({ entity: cube });
  4. Run the script. Press Run The Code, the play button at the lower left.

    A cube one number sizes, step 4 in the TypeScript editor: Run The Code pressed and the result drawn in the 3D view beside the code
  5. Change const size = 3; to const size = 5;.

    Change the one number, run again, and the cube follows.

  6. Run the script. Press Run The Code, the play button at the lower left.

    A cube one number sizes, step 6 in the TypeScript editor: Run The Code pressed and the result drawn in the 3D view beside the code

The finished script​

The script these steps build, to run here:

Bitbybit Platform

A cube one number sizes

typescript logoTypescript
Script Source (typescript)
const size = 5;
const cubeOptions = new Bit.Inputs.OCCT.CubeDto();
cubeOptions.size = size;
const cube = await bitbybit.occt.shapes.solid.createCube(cubeOptions);
await bitbybit.draw.drawAnyAsync({ entity: cube });

What you learned​

  • One value can drive a model. Every line that reads size follows it.
  • The API follows its categories, bitbybit.occt.shapes.solid.createCube sitting where the cube does in Rete and Blockly.
  • Split a growing script into files with files and imports.

Verified against the product in October 2026