OpenSCAD User Manual/Include Statement
From Wikibooks, open books for an open world
The text in its current form is incomplete.
For including code from external files in OpenSCAD, there are two commands available:
include <filename>acts as if the contents of the included file were written in the including file, anduse <filename>imports modules and functions, but does not execute any commands other than those definitions.
A library file for generating rings might look like this (defining a function and providing an example):
ring.scad:
module ring(r1, r2, h) {
difference() {
cylinder(r = r1, h = h);
translate([ 0, 0, -1 ]) cylinder(r = r2, h = h+2);
}
}
ring(5, 4, 10);
Including the library using
include <ring.scad>; rotate([90, 0, 0]) ring(10, 1, 1);
would result in the example ring being shown in addition to the rotated ring, but
use <ring.scad>; rotate([90, 0, 0]) ring(10, 1, 1);
only shows the rotated ring.