Skip to content

Creating a Module

Beginner

Build a reusable cup() module so you can generate hollow cylinders in different sizes without rewriting geometry each time.

What you'll build

A reusable OpenSCAD module cup(height, radius, wall, bottom).

Why this helps

Can be used across multiple projects, easily created hollowed cylinder

Save this as cup.scad:

module cup(height, radius, wall, bottom) {
difference() {
cylinder(h = height, r = radius, center = true);
translate([0, 0, bottom])
cylinder(h = height, r = radius - wall, center = true);
}
}

Parameter guide:

ParameterMeaning
heightTotal cup height
radiusOuter radius
wallWall thickness
bottomVertical offset for the inner cutout (controls bottom thickness)

Import the module file with use, then call cup(...) with your desired dimensions.

use <cup.scad>;
$fn = 92;
cup(63, 32, 3, 3);