Finally, here is a compact quick reference of the most important OpenSCAD functions and their parameters.
circle(
r, // radius
d // or diameter
);
square(
size, // a single value creates a square,
// a two-dimensional vector a rectangle
center // if true, the rectangle is centered over the origin
);
polygon(
points, // array of two-dimensional vectors as set of points
paths, // optional array with point indices if the polygon has also
// inner "negative" paths
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
);
text(
text, // the text as string
size, // the height of a standard uppercase letter
font, // the font name as string (project 6)
halign, // horizontal alignment given as string
// possible values: "left", "center", "right"
valign, // vertical alignment given as string
// possible values: "top", "center", "baseline", "bottom"
spacing, // adjustment factor to influence spacing between letters
direction, // writing direction, possible values:
// "ltr" -> from left to right
// "rtl" -> from right to left
// "ttb" -> from top to bottom
// "btt" -> from bottom to top
language, // language given as short string. "en", "de", ...
script // lettering system, default value is "latin"
);
import(
file, // filename of a `.svg`- or `.dxf`-file
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
layer // layer name in case of a `.dxf`-file
);
projection(
cut // if "true", the subsequent geometrie is cut in the X-Y-Plane
// instead of being projected onto it
);
sphere(
r, // radius
d // or diameter
);
cube(
size, // a single value results in a cube
// a three-dimensional vector results in a cuboid a.k.a. box
center // if "true", the box is centered around the origin
);
cylinder(
h, // height of the cylinder
r, // radius, or alternatively
r1, // lower radius and
r2, // upper radius
d, // diameter, or alternatively
d1, // lower diameter and
d2, // upper diameter
center // if "true", the cylinder is centered along the Z-Axis
);
polyhedron(
points, // array of three-dimensional vectors representing a point set
faces, // array of four-dimensional vectors with each vector
// a surface tile whose edge points are given as indices into
// the points array
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
);
import(
file, // filename of a `.stl`, `.off`, `.amf` or `.3mf`-file
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
);
surface(
file, // filename of a `.png`-file or text file
center, // if "true", the generated object will be centered
invert, // if "true", the color interpretation will be inverted
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
);
linear_extrude(
height, // extrusion length
center, // if "true", the Extrusion will be centered along the Z-axis
twist, // twist in degrees around the Z-axis
slices, // number of layers along the Z-axis
scale, // Scaling of the base shape along the extrusion. Either a
// single value or a two-dimensional vector that defines the
// scaling in X- and Y-direction separately
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
)
a_2D_geometry();
rotate_extrude(
angle, // angle of the extrusion around the Z-axis
convexity // Optimization parameters for preview. If you experience
// rendering errors in preview, increase this value. A value
// of 10 should work in most cases.
)
a_2D_geometry();
translate(
v // a two- or three-dimensional vector that describes the translation
// relative to the origin
)
a_geometry();
rotate(
a, // either a single rotation angle (in conjunction with v)
// or a three-dimensional vector that describes the rotation
// angles around the X-, Y-, and Z-axis
v // a three-dimensional vector that describes the rotational axis
)
a_geometry();
scale(
v // a two- or three-dimensional vector that describes the scaling
// of the geometry in X-, Y- and Z-direction
)
a_geometry();
resize(
newsize // a two- or three-dimensional vector that describes the
// new dimensions of the subsequent geometry. Values of 0 are
// interpreted as "auto scale"
)
a_geometry();
mirror(
v // a two- or three-dimensional vector that describes the axis along
// which the geometry should be mirrored
)
a_geometry();
color(
c, // either a four-dimensional vector that describes the color as
// RGBA with values ranging from 0 to 1; or
// a three-dimensional vector that describes the color as RGB with
// values ranging from 0 to 1; or
// a string that describes the color as hexadecimal code with a
// leading '#'; or
// a string that describes the color with a color name like "red"
alpha // a transparency value ranging from 0 (transparent) to 1 (opaque)
)
a_geometry();
hull(){
a_geometry(); // the convex hull is formed over all elements of the
// geometry set
a_geometry();
...
}
offset(
r, // expansian using a circle with radius r that is moved along
// the 2D-shape. alternatively:
delta, // distance to the new outer shape from the original shape.
// Compared to `r` sharp corners will not be rounded when using
// delta.
chamfer // if "true", corners will be flattened (only in conjunction
// with delta)
)
a_2D_geometry();
minkowski() {
a_geometry(); // base geometry
a_geometry(); // geometry that is copied at every point of the base
// geometry to expand the point set of the base geometry
}
multmatrix(
m // a 4x3 or 4x4 transformation matrix that describes the affine
// transformation of the geometry
)
a_geometry();
union(){
a_geometry(); // all geometries of the geometry set will be united
a_geometry();
...
}
difference(){
a_geometry(); // base geometry
a_geometry(); // all geometries after the base geometry will be
// substracted from the base geometry
...
}
intersection(){
a_geometry(); // all geometries of the geometry set will be intersected
a_geometry();
...
}
for ( i = [start : step : stop] ) // loop variable i goes from
a_geometry(); // start to stop with increments of
// step (optional)
for ( v = array ) // loop variable v goes through all
a_geometry(); // entries of the array
for ( i ... , j ... ) // multiple loop variables are separated
a_geometry(); // by commas
intersection_for( ... ) // same operation as regular for-loop,
a_geometry(); // but objects are intersected instead of unified
array = [ for (i = ...) i ]; // generates an array using a for-loop
absolute value: abs()
sign of a value: sign()
sine: sin()
cosine: cos()
tangent: tan()
arcsine: asin()
arccosine: acos()
arctangent: atan()
arctangent 2: atan2()
round down floor()
round round()
round up ceil()
natural logarithm ln()
base 10 logarithm log()
natural exponential function exp()
power function pow()
square root sqrt()
minimum min()
maximum max()
length of a vector norm()
cross product of two vectors cross()
number of elements in an array len()
number of letters in a string len()
concatenate arrays concat()
convert parameters into string str()
search in arrays search()
character conversions chr(), ord()
let (x = ...) {
}
array = rands (
min_value, // smallest random value
max_value, // biggest random value
value_count, // number of random values
seed_value // random seed
)
module test() {
$children // number of elements in the outer geometry set
children( i ); // i-th Geometry of the outer geometry set.
// If no index is provided, all geometries of the
// geometry set are returned
}