OpenSCAD Cheat Sheet: Essential Commands for 3D Modeling
Published: February 21, 2026
Quick Reference Overview
This is the cheat sheet I wish I'd had when learning OpenSCAD. Bookmark it—you'll be back. If you're brand new, check out our OpenSCAD Tutorial first, or generate OpenSCAD code from a photo and learn by studying real examples.
🔲 3D Primitives
Your building blocks. Everything complex starts with these:
| Command | Description | Example |
|---|---|---|
cube(size) |
Creates a cube or box | cube(10); or cube([10, 20, 5]); |
sphere(r) |
Creates a sphere | sphere(r=15); or sphere(d=30); |
cylinder(h, r) |
Creates a cylinder or cone | cylinder(h=20, r=10); |
cylinder(h, r1, r2) |
Creates a cone/tapered cylinder | cylinder(h=20, r1=15, r2=5); |
polyhedron(points, faces) |
Creates custom 3D shape from vertices | polyhedron(points=[[...]], faces=[[...]]); |
// Cube with size [width, depth, height]
cube([30, 20, 10]);
// Centered cube
cube([30, 20, 10], center=true);
// Smooth sphere ($fn controls resolution)
sphere(r=10, $fn=64);
◻️ 2D Primitives
Flat shapes you'll extrude into 3D later:
| Command | Description | Example |
|---|---|---|
square(size) |
Creates a rectangle | square([20, 10]); |
circle(r) |
Creates a circle | circle(r=10, $fn=64); |
polygon(points) |
Creates custom 2D shape | polygon([[0,0], [10,0], [5,10]]); |
text(str) |
Creates 2D text | text("Hello", size=10); |
↕️ Extrusion (2D → 3D)
Turn flat shapes into 3D. This is where the magic happens:
| Command | Description | Example |
|---|---|---|
linear_extrude(height) |
Extrude 2D shape straight up | linear_extrude(10) circle(r=5); |
linear_extrude(height, twist) |
Extrude with rotation | linear_extrude(20, twist=90) square(10); |
linear_extrude(height, scale) |
Extrude with taper | linear_extrude(20, scale=0.5) circle(10); |
rotate_extrude() |
Spin 2D shape around Z axis | rotate_extrude() translate([10,0]) circle(3); |
// 3D text
linear_extrude(5)
text("OpenSCAD", size=12, font="Arial:style=Bold");
// Twisted column
linear_extrude(50, twist=180, $fn=64)
square([10, 10], center=true);
🔄 Transformations
Position things where you want them:
| Command | Description | Example |
|---|---|---|
translate([x, y, z]) |
Move object | translate([10, 0, 5]) cube(5); |
rotate([x, y, z]) |
Rotate around axes (degrees) | rotate([0, 0, 45]) cube(10); |
scale([x, y, z]) |
Resize object | scale([2, 1, 0.5]) cube(10); |
mirror([x, y, z]) |
Mirror across plane | mirror([1, 0, 0]) cube(10); |
resize([x, y, z]) |
Resize to exact dimensions | resize([20, 20, 0], auto=true) sphere(10); |
color("name") |
Set preview color | color("red") cube(10); |
🔗 Boolean Operations (CSG)
The heart of OpenSCAD. Combine simple shapes into complex ones:
| Command | Description | Use Case |
|---|---|---|
union() |
Combine shapes together | Join multiple parts into one |
difference() |
Subtract subsequent shapes from first | Create holes, cutouts |
intersection() |
Keep only overlapping regions | Create complex shapes from overlaps |
// Cube with a cylindrical hole
difference() {
cube([20, 20, 10], center=true);
cylinder(h=12, r=5, center=true, $fn=32);
}
// Two overlapping spheres combined
union() {
sphere(r=10);
translate([8, 0, 0]) sphere(r=10);
}
📦 Modules (Reusable Components)
Don't repeat yourself. Define a shape once, use it everywhere:
// Define a module
module rounded_box(size, radius) {
minkowski() {
cube([size[0]-radius*2, size[1]-radius*2, size[2]/2]);
cylinder(r=radius, h=size[2]/2, $fn=32);
}
}
// Use the module
rounded_box([30, 20, 10], 3);
🔁 Loops and Conditionals
Generate patterns, arrays, and conditional features:
// Create a row of cylinders
for (i = [0 : 5]) {
translate([i * 15, 0, 0])
cylinder(h=10, r=5);
}
// Circular array
for (i = [0 : 360/6 : 360]) {
rotate([0, 0, i])
translate([20, 0, 0])
cylinder(h=5, r=3);
}
// Conditional geometry
if (add_hole) {
difference() {
cube(20);
cylinder(h=22, r=5);
}
} else {
cube(20);
}
⚙️ Special Variables
| Variable | Description | Typical Value |
|---|---|---|
$fn |
Number of fragments (resolution) | $fn=64 for smooth curves |
$fa |
Minimum angle for fragment | $fa=1 (degrees) |
$fs |
Minimum size of fragment | $fs=0.5 (mm) |
Pro tip: Use $fn=32 while designing (previews render in seconds). Bump it to $fn=128 or higher only for your final export—otherwise you're just watching progress bars.
⌨️ Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| F5 | Preview (fast, approximate) |
| F6 | Render (slow, accurate) |
| F7 | Export STL |
| Ctrl + D | Comment/uncomment line |
| Ctrl + Shift + V | View all (reset camera) |
💡 Pro Tips
- Debug visually: Prefix shapes with
%to make them transparent, or#to highlight them red. Saves tons of head-scratching. - Speed vs. quality: Low
$fnwhile working, high$fnonly at the end - DRY principle: If you're copy-pasting geometry, make it a module instead
- Comment everything: Future you won't remember what
translate([37.5, 0, 0])was for - Don't start from scratch: Generate OpenSCAD from photos to get working code in minutes
Skip the Blank Page
Staring at an empty .scad file? Generate working code from a photo instead. Then use this cheat sheet to tweak it.
Generate OpenSCAD from Photo