OpenSCAD Skill
Create, validate, and export OpenSCAD 3D models. Supports parameter customization, visual preview from multiple angles, and STL export for 3D printing platforms like MakerWorld.
Prerequisites
OpenSCAD must be installed. Install via Homebrew:
bash
1brew install openscad
This skill provides several tools in the tools/ directory:
Preview Generation
bash
1# Generate a single preview image
2./tools/preview.sh model.scad output.png [--camera=x,y,z,tx,ty,tz,dist] [--size=800x600]
3
4# Generate multi-angle preview (front, back, left, right, top, iso)
5./tools/multi-preview.sh model.scad output_dir/
STL Export
bash
1# Export to STL for 3D printing
2./tools/export-stl.sh model.scad output.stl [-D 'param=value']
bash
1# Extract customizable parameters from an OpenSCAD file
2./tools/extract-params.sh model.scad
Validation
bash
1# Check for syntax errors and warnings
2./tools/validate.sh model.scad
Visual Validation (Required)
Always validate your OpenSCAD models visually after creating or modifying them.
After writing or editing any OpenSCAD file:
- Generate multi-angle previews using
multi-preview.sh
- View each generated image using the
read tool
- Check for issues from multiple perspectives:
- Front/back: Verify symmetry, features, and proportions
- Left/right: Check depth and side profiles
- Top: Ensure top features are correct
- Isometric: Overall shape validation
- Iterate if needed: If something looks wrong, fix the code and re-validate
This catches issues that syntax validation alone cannot detect:
- Inverted normals or inside-out geometry
- Misaligned features or incorrect boolean operations
- Proportions that don't match the intended design
- Missing or floating geometry
- Z-fighting or overlapping surfaces
Never deliver an OpenSCAD model without visually confirming it looks correct from multiple angles.
Workflow
1. Creating an OpenSCAD Model
Write OpenSCAD code with customizable parameters at the top:
openscad
1// Customizable parameters
2wall_thickness = 2; // [1:0.5:5] Wall thickness in mm
3width = 50; // [20:100] Width in mm
4height = 30; // [10:80] Height in mm
5rounded = true; // Add rounded corners
6
7// Model code below
8module main_shape() {
9 if (rounded) {
10 minkowski() {
11 cube([width - 4, width - 4, height - 2]);
12 sphere(r = 2);
13 }
14 } else {
15 cube([width, width, height]);
16 }
17}
18
19difference() {
20 main_shape();
21 translate([wall_thickness, wall_thickness, wall_thickness])
22 scale([1 - 2*wall_thickness/width, 1 - 2*wall_thickness/width, 1])
23 main_shape();
24}
Parameter comment format:
// [min:max] - numeric range
// [min:step:max] - numeric range with step
// [opt1, opt2, opt3] - dropdown options
// Description text - plain description
2. Validate the Model
bash
1./tools/validate.sh model.scad
3. Generate Previews
Generate preview images to visually validate the model:
bash
1./tools/multi-preview.sh model.scad ./previews/
This creates PNG images from multiple angles. Use the read tool to view them.
4. Export to STL
bash
1./tools/export-stl.sh model.scad output.stl
2# With custom parameters:
3./tools/export-stl.sh model.scad output.stl -D 'width=60' -D 'height=40'
Camera Positions
Common camera angles for previews:
- Isometric:
--camera=0,0,0,45,0,45,200
- Front:
--camera=0,0,0,90,0,0,200
- Top:
--camera=0,0,0,0,0,0,200
- Right:
--camera=0,0,0,90,0,90,200
Format: x,y,z,rotx,roty,rotz,distance
MakerWorld Publishing
For MakerWorld, you typically need:
- STL file(s) exported via
export-stl.sh
- Preview images (at least one good isometric view)
- A description of customizable parameters
Consider creating a model.json with metadata:
json
1{
2 "name": "Model Name",
3 "description": "Description for MakerWorld",
4 "parameters": [...],
5 "tags": ["functional", "container", "organizer"]
6}
Example: Full Workflow
bash
1# 1. Create the model (write .scad file)
2
3# 2. Validate syntax
4./tools/validate.sh box.scad
5
6# 3. Generate multi-angle previews
7./tools/multi-preview.sh box.scad ./previews/
8
9# 4. IMPORTANT: View and validate ALL preview images
10# Use the read tool on each PNG file to visually inspect:
11# - previews/box_front.png
12# - previews/box_back.png
13# - previews/box_left.png
14# - previews/box_right.png
15# - previews/box_top.png
16# - previews/box_iso.png
17# Look for geometry issues, misalignments, or unexpected results.
18# If anything looks wrong, go back to step 1 and fix it!
19
20# 5. Extract and review parameters
21./tools/extract-params.sh box.scad
22
23# 6. Export STL with default parameters
24./tools/export-stl.sh box.scad box.stl
25
26# 7. Export STL with custom parameters
27./tools/export-stl.sh box.scad box_large.stl -D 'width=80' -D 'height=60'
Remember: Never skip the visual validation step. Many issues (wrong dimensions, boolean operation errors, inverted geometry) are only visible when you actually look at the rendered model.
OpenSCAD Quick Reference
Basic Shapes
openscad
1cube([x, y, z]);
2sphere(r = radius);
3cylinder(h = height, r = radius);
4cylinder(h = height, r1 = bottom_r, r2 = top_r); // cone
openscad
1translate([x, y, z]) object();
2rotate([rx, ry, rz]) object();
3scale([sx, sy, sz]) object();
4mirror([x, y, z]) object();
Boolean Operations
openscad
1union() { a(); b(); } // combine
2difference() { a(); b(); } // subtract b from a
3intersection() { a(); b(); } // overlap only
Advanced
openscad
1linear_extrude(height) 2d_shape();
2rotate_extrude() 2d_shape();
3hull() { objects(); } // convex hull
4minkowski() { a(); b(); } // minkowski sum (rounding)
2D Shapes
openscad
1circle(r = radius);
2square([x, y]);
3polygon(points = [[x1,y1], [x2,y2], ...]);
4text("string", size = 10);