Tinkercad

Tinkercad Codeblocks Tutorial: Designing Shapes with Code

Learn Tinkercad Codeblocks: the interface, shape and modify blocks, holes and groups, loops for patterns, variables for parametric designs, and export.

On this page
  1. What Codeblocks is
  2. Getting started
  3. The Codeblocks interface
  4. Your first program: a block with a hole
  5. Moving, rotating and scaling
  6. Loops: making patterns
  7. Variables: making parametric designs
  8. Exporting your Codeblocks design
  9. Tips and next steps

Codeblocks is Tinkercad’s block-based coding workspace. Instead of dragging shapes onto a workplane, you stack code blocks that create, move and combine shapes, a bit like Scratch for 3D. It’s a gentle way to learn programming concepts, and it’s also the one part of Tinkercad where changing a single number can update an entire design.

Block names and colors below reflect how Codeblocks has generally looked. Small details may differ in your version.

What Codeblocks is

  • A visual programming environment: you snap blocks together instead of typing code.
  • Free, and part of Tinkercad alongside 3D Design and Circuits.
  • Good for patterns, repetition and parametric shapes, which are tedious to build by hand.
  • Popular in classrooms for teaching loops, variables and coordinates.

Getting started

  1. Sign in to Tinkercad.
  2. From your dashboard, choose to create a new Codeblocks design. It’s usually under the Create button alongside 3D Design and Circuits.
  3. A blank Codeblocks editor opens. Tinkercad also offers starter examples and guided lessons, which are worth trying.

The Codeblocks interface

  • Block panel (left): categories of blocks, such as Shapes, Modify, Control, Math and Data (variables).
  • Code canvas (center): where you drag and stack blocks. Blocks run from top to bottom.
  • 3D viewer (right): shows the result when you run the code.
  • Run / Play button: runs your program and builds the model. A speed setting lets you watch it build step by step or jump straight to the result.

Your first program: a block with a hole

  1. From Shapes, drag a Box block onto the canvas.
  2. Open the block’s settings (usually a small arrow or the block’s fields) and set width, length and height, for example 40, 40 and 10.
  3. Drag a Cylinder block beneath it. Set its size, for example 10 × 10 × 20, and change it from Solid to Hole.
  4. From Modify, add a Create Group block after both shapes. This works like Group in 3D Design: it combines the shapes and subtracts the hole.
  5. Click Run.

You’ll see a square plate with a hole through the center. The logic is exactly the solid-and-hole system from 3D Design; see grouping objects and using holes in Tinkercad.

Moving, rotating and scaling

Modify blocks change the most recently created shape or group:

  • Move: shift a shape by an amount along X, Y and Z
  • Rotate: turn it by a number of degrees around an axis
  • Scale: resize it by a factor along each axis

For example: create a box, then add Move with X = 30 to shift it 30 units sideways. Order matters. Modify blocks act on what came before them, so rotating then moving gives a different result from moving then rotating.

Loops: making patterns

Loops are where Codeblocks shines. In Control, the Repeat block runs the blocks inside it a set number of times.

A row of cylinders:

  1. Add a Repeat 6 times block.
  2. Inside it, place a Cylinder block followed by a Move block with X = 15.

Each time through the loop, Codeblocks creates a cylinder and moves it along, producing a row of six. In practice you may need a variable to step the position (see below), depending on how Move applies inside the loop in your version. Run it and adjust.

A ring of shapes:

  1. Add a Repeat 12 times block.
  2. Inside it: create a small Box, Move it outward (for example X = 30), then Rotate it around Z by a counter variable × 30°.

The result is twelve boxes evenly spaced around a circle. This is far quicker than placing them by hand in 3D Design (compare how to duplicate in Tinkercad).

Variables: making parametric designs

Data blocks let you create variables, named values you can reuse.

A resizable box with walls:

  1. Create variables such as width = 50, depth = 30, height = 20 and wall = 2.
  2. Create a solid Box using width, depth and height.
  3. Create a hole Box using width − 2 × wall, depth − 2 × wall and height, using Math blocks for the arithmetic, then move it up by wall.
  4. Group them.

Now change width to 80 and run again. The whole box, including its walls, updates. This is the parametric behavior 3D Design lacks (see what are the disadvantages of Tinkercad?), and it’s the same calculation described in how to hollow out an object in Tinkercad.

Exporting your Codeblocks design

When your design is ready, look for the Export option in the Codeblocks editor. Tinkercad has offered options such as:

  • Download as STL or OBJ for 3D printing
  • Export an animated GIF of the model being built
  • Bringing the result into a 3D Design, where you can keep editing with normal tools

Once in 3D Design, the shapes are regular Tinkercad shapes. They’re no longer linked to the code, so make parametric changes in Codeblocks first. For export details, see how to turn Tinkercad into an STL file.

Tips and next steps

  • Start from examples. Tinkercad’s starter projects and lessons show useful block patterns you can adapt.
  • Run often. Small changes are easier to debug.
  • Slow down the run speed to see which block creates which shape.
  • Name variables clearly. holeDiameter is easier to understand than x.
  • Keep designs reasonably simple. Very large loops can make the viewer slow.

When you outgrow Codeblocks, code-based tools such as OpenSCAD, or BlocksCAD for another block-based option, take the same ideas further. See software like Tinkercad.

The complete guide to tinkercad

Tinkercad Tutorial: How to Design in 3D with Tinkercad
Read the guide

Keep exploring

Guides from other topics

All topics →