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 Blockly a parameter is often a variable, a named value set once and read wherever it is needed. Here a variable sizes a cube made by OCCT, the CAD kernel behind solids on Bitbybit.

Before you start​

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

The steps​

  1. Make a variable named size. Open variables in the toolbox, press Create variable..., type size and press Create.

    A variable is a named value you set once and use anywhere. Making one adds its blocks to the variables category.

    A cube a variable sizes, step 1 in the Blockly editor: the variable size made with Create variable..., its blocks now in the variables category
  2. Add set size to. Open variables in the toolbox and drag set size to onto the workspace.

    A cube a variable sizes, step 2 in the Blockly editor: the toolbox open at variables, the way there numbered and the block to drag ringed in the flyout
  3. Add number. Open math blockly in the toolbox and drag number onto the workspace.

    A cube a variable sizes, step 3 in the Blockly editor: the toolbox open at math blockly, the way there numbered and the block to drag ringed in the flyout
  4. Plug number into the value of set size to. Drag it by its left edge onto that input until it snaps in.

  5. Set number to 3.

    The variable now holds 3.

    A cube a variable sizes, step 5 in the Blockly editor: a value set to 3, ringed on its block
  6. Add draw any async no return. Open draw > draw async in the toolbox and drag draw any async no return onto the workspace.

  7. Put draw any async no return under set size to. Drag it below until it snaps on.

    Stacked under the variable, the drawing runs after it is set.

    A cube a variable sizes, step 7 in the Blockly editor: one block stacked under another, ringed where it snapped
  8. Add cube. Open occt > shapes > solid > primitives in the toolbox and drag cube onto the workspace.

    The toolbox follows the API: occt, then shapes, then solid. The cube is a solid made by OCCT, the CAD kernel.

    A cube a variable sizes, step 8 in the Blockly editor: the toolbox open at occt, shapes, solid, primitives, the way there numbered and the block to drag ringed in the flyout
  9. Plug cube into the entity of draw any async no return. Drag it by its left edge onto that input until it snaps in.

    A cube a variable sizes, step 9 in the Blockly editor: a block plugged into the Entity input of another, ringed where it snapped
  10. Take the value out of the size of cube. Drag the block out of that input and drop it on the trash can.

Drag the number out of the cube's size and drop it on the trash can: the variable will give the size instead.

A cube a variable sizes, step 10 in the Blockly editor: a block dragged out of its input and dropped on the trash can
  1. Add size. Open variables in the toolbox and drag size onto the workspace.

  2. Plug size into the size of cube. Drag it by its left edge onto that input until it snaps in.

The cube's size is now whatever the variable holds.

A cube a variable sizes, step 12 in the Blockly editor: a block plugged into the Size input of another, ringed where it snapped
  1. Run the script. Press Run The Code, the play button at the lower left.

Run it. Change the 3 and run again, and the cube follows: every block that reads size gets the new value.

A cube a variable sizes, step 13 in the Blockly editor: Run The Code pressed and the result drawn in the 3D view beside the workspace

The finished script​

The script these steps build, to run here:

Bitbybit Platform

A cube a variable sizes

blockly logoBlockly
Script Source (blockly)
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="size">size</variable></variables><block type="variables_set" x="40" y="40"><field name="VAR" id="size">size</field><value name="VALUE"><block type="math_number"><field name="NUM">3</field></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="bitbybit.occt.shapes.solid.createCube"><value name="Size"><block type="variables_get"><field name="VAR" id="size">size</field></block></value><value name="Center"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="OriginOnCenter"><block type="logic_boolean"><field name="BOOL">TRUE</field></block></value></block></value></block></next></block></xml>

What you learned​

  • Variables hold a value under a name: set it with set … to and read it with the variable's own block. Variables and functions has more.
  • The toolbox follows the API. The cube sits at occt, shapes, solid, as bitbybit.occt.shapes.solid.createCube does in TypeScript.
  • The trash can takes any block you drop on it.

Verified against the product in October 2026