OpenSCAD User Manual/The OpenSCAD Language
[edit] The OpenSCAD Language
Contents |
[edit] General
The text in its current form is incomplete.
[edit] Comments
OpenSCAD uses C++-style comments:
// This is a comment myvar = 10; // The rest of the line is a comment /* Multi-line comments can span multiple lines. */
[edit] Variables
Variables in OpenSCAD are simply a name followed by an assignment via an expression
Example:
myvar = 5 + 4;
[edit] Strings
Explicit double quotes or backslashes need to be escaped (\" and \\ respectively). Other escaped special characters are newlines (\n), tabs (\t) and carriage returns (\r).
NB! This behavior is new since OpenSCAD-2001.04. You can upgrade old files using the following sed command: sed 's/\\/\\\\/' non-escaped.scad > escaped.scad
Example:
echo("The quick brown fox \tjumps \"over\" the lazy dog.\rThe quick brown fox.\nThe \\lazy\\ dog.");
Output:
ECHO: "The quick brown fox jumps "over" the lazy dog.
The quick brown fox.
The \lazy\ dog."
[edit] Variables are set at compile-time, not run-time
Note: Because OpenSCAD calculates its variable values at compile-time, not run-time, the last variable assignment will apply everywhere the variable is used. It may be helpful to think of them as overrideable constants rather than as variables.
Example:
// The value of 'a' reflects only the last set value a = 0; echo(a); a = 5; echo(a);
Output
ECHO: 5 ECHO: 5
This behavior however is scoped to either the root or to a specific call to a module, meaning you can re-define a variable within a module without affecting its value outside of it. However, all instances within that call will behave as described above with the last-set value being used throughout.
Example:
p = 4; test(5); echo(p); p = 6; test(8); echo(p); module test(q) { p = 2 + q; echo(p); p = 4 + q; echo(p); }
Output
ECHO: 9 ECHO: 9 ECHO: 6 ECHO: 12 ECHO: 12 ECHO: 6
While this appears to be counter-intuitive, it allows you to do some interesting things: For instance, if you set up your shared library files to have default values defined as variables at their root level, when you include that file in your own code, you can 're-define' or override those constants by simply assigning a new value to them.
See the assign for more tightly scoped changing of values.
[edit] Getting input
Now we have variables, it would be nice to be able to get input into them instead of setting the values from code. There are a few functions to read data from DXF files, or you can set a variable with the -D switch on the command line.
Getting a point from a drawing
Getting a point is useful for reading an origin point in a 2D view in a technical drawing. The function builtin_dxf_cross will read the intersection of two lines on a layer you specify and return the intersection point. This means that the point must be given with two lines in the DXF file, and not a point entity.
OriginPoint = builtin_dxf_cross(filename="drawing.dxf", layername="SCAD.Origin", origin=[0, 0], scale=1);
Getting a dimension value
You can read dimensions from a technical drawing. This can be useful to read a rotation angle, an extrusion height, or spacing between parts. In the drawing, create a dimension that does not show the dimension value, but an identifier. To read the value, you specify this identifier from your script:
TotalWidth = builtin_dxf_dim(filename="drawing.dxf", layername="SCAD.Dims", name="TotalWidth", origin=[0, 0], scale=1);
For a nice example of both functions, see Example009 and the image on the homepage of OpenSCAD.
[edit] Conditional and Iterator Functions
[edit] For Loop
Iterate over the values in a vector or range.
Vector version: for (variable=<vector>) <do_something> - <variable> is assigned to each successive value in the vector
Range version: for (variable=<range>) <do_something>
Range: [<start>:<end>] - iterate from start to end inclusive. Also works if if <end> is smaller than <start>
Range: [<start>:<increment>:<end>] - iterate from start to end with the given increment. The increment can be a fraction Note: The increment is given as an absolute value and cannot be negative. If <end> is smaller than <start> the increment should remain unchanged.
| Usage example 1 - iteration over a vector: | |
for (z = [-1, 1]) // two iterations, z = -1, z = 1 { translate([0, 0, z]) cube(size = 1, center = false); } |
| Usage example 2a - iteration over a range: | |
for ( i = [0 : 5] ) { rotate( i * 360 / 6, [1, 0, 0]) translate([0, 10, 0]) sphere(r = 1); } |
| Usage example 2b - iteration over a range specifying an increment: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Note: The middle parameter in the range designation // ('0.2' in this case) is the 'increment-by' value for ( i = [0 : 0.2 : 5] ) { rotate( i * 360 / 6, [1, 0, 0]) translate([0, 10, 0]) sphere(r = 1); } }
[edit] Intersection For LoopIterate over the values in a vector or range and take an intersection of the contents. Note: Parameters
[edit] If StatementConditionally evaluate a sub-tree. Parameters
Usage example: if (x > y) { cube(size = 1, center = false); } else { cube(size = 2, center = true); } [edit] Assign StatementSet variables to a new value for a sub-tree. Parameters
Usage example: for (i = [10:50]) { assign (angle = i*360/20, distance = i*10, r = i*2) { rotate(angle, [1, 0, 0]) translate([0, distance, 0]) sphere(r = r); } } [edit] Mathematical OperatorsThe text in its current form is incomplete. [edit] Logical OperatorsAll logical operators take Boolean values as operands and produce a Boolean value.
[edit] Relational OperatorsAll relational operator take numbers as operands and produce a Boolean value. The equal and not-equal operators can also compare Boolean values.
[edit] Scalar Arithmetical OperatorsThe scalar arithmetical operators take numbers as operands and produce a new number.
The "-" can also be used as prefix operator to negate a number. [edit] Vector OperatorsThe vector operators take vectors as operands and produce a new vector;
The "-" can also be used as prefix operator to element-wise negate a vector. [edit] Vector-Number OperatorsThe vector-number operators take a vector and a number as operands and produce a new vector;
[edit] Conditional OperatorsThe ?: operator can be used to conditionally evaluate one or another expression. It works like the ?: operator from the family of C-like programming languages. Example given: x>0 ? "pos" : "neg" [edit] Mathematical FunctionsThe text in its current form is incomplete. [edit] absMathematical absolute value function. Returns the positive value of a signed decimal number. Usage examples: abs(-5.0); abs(0); abs(8.0); Results: 5.0 0.0 8.0 [edit] acosMathematical arccosine, or inverse cosine, function. [edit] asinMathematical arcsine, or inverse sine, function. [edit] atanMathematical arctangent, or inverse tangent, function. Returns the principal value of the arc tangent of x, expressed in degrees. See: atan function [edit] atan2Mathematical two-argument atan function. Returns the principal value of the arc tangent of y/x, expressed in degrees. See: atan2 [edit] ceilMathematical ceiling function. See: Ceil Function [edit] cosMathematical cosine function.
[edit] expMathematical exp function. Returns the base-e exponential function of x, which is the number e raised to the power x. See: Exponent [edit] floorMathematical floor function. See: Floor Function [edit] lnMathematical natural logarithm. See: Natural logarithm [edit] logMathematical logarithm. See: Logarithm [edit] lookup(Inserted by a beginner, may need fixing!) From a given key-value array, it will interpolate a value for any key using linear interpolation. Parameters
[edit] maxReturns the maximum of the two parameters. Parameters
Usage Example: max(3.0,5.0); max(8.0,3.0); Results: 5.0 8.0 [edit] minReturns the minimum of the two parameters. Parameters
Usage Example: min(3.0,5.0); min(8.0,3.0); Results: 3.0 3.0 [edit] powMathematical power function. Parameters
Usage examples:
for (i = [0:5]) {
translate([i*25,0,0]) {
cylinder(h = pow(2,i)*5, r=10);
echo (i, pow(2,i));
}
}
[edit] randsRandom number generator. Parameters
Usage Examples:
seed=42;
random_vect=rands(5,15,4,seed);
echo( "Random Vector: ",random_vect);
sphere(r=5);
for(i=[0:3]) {
rotate(360*i/4) {
translate([10+random_vect[i],0,0])
sphere(r=random_vect[i]/2);
}
}
[edit] roundThe "round" operator returns the greatest or least integer part, respectively, if the numeric input is positive or negative. Some examples: round(x.5) = x+1. round(x.49) = x. round(-(x.5)) = -(x+1). round(-(x.49)) = -x. [edit] signMathmatical signum function. Returns a unit value that extracts the sign of a value see: Signum function Parameters
Usage examples: sign(-5.0); sign(0); sign(8.0); Results: -1.0 0.0 1.0 [edit] sinMathematical sine function. Parameters
Usage example 1
for (i = [0:5]) {
echo(360*i/6, sin(360*i/6)*80, cos(360*i/6)*80);
translate([sin(360*i/6)*80, cos(360*i/6)*80, 0 ])
cylinder(h = 200, r=10);
}
[edit] sqrtMathematical square root function.
translate([sqrt(100),0,0])sphere(100); [edit] tanMathematical tangent function. Parameters
Usage examples:
for (i = [0:5]) {
echo(360*i/6, tan(360*i/6)*80);
translate([tan(360*i/6)*80, 0, 0 ])
cylinder(h = 200, r=10);
}
[edit] String FunctionsThe text in its current form is incomplete. [edit] strConvert all arguments to strings and concatenate. Usage examples:
number=2;
echo ("This is ",number,3," and that's it.");
echo (str("This is ",number,3," and that's it."));
Results: ECHO: "This is ", 2, 3, " and that's it." ECHO: "This is 23 and that's it." [edit] Primitive SolidsThe text in its current form is incomplete. [edit] cubeCreates a cube at the origin of the coordinate system. When center is true the cube will be centered on the origin, otherwise it is created in the first octant. The argument names are optional if the arguments are given in the same order as specified in the parameters
Usage examples: cube(size = 1, center = false); cube(size = [1,2,3], center = true); [edit] sphereCreates a sphere at the origin of the coordinate system. The argument name is optional. Parameters
sphere(r = 1); sphere(r = 5); sphere(r = 10); // this will create a high resolution sphere with a 2mm radius sphere(2, $fn=100); // will also create a 2mm high resolution sphere but this one // does not have as many small triangles on the poles of the sphere sphere(2, $fa=5, $fs=0.1); [edit] cylinderCreates a cylinder at the origin of the coordinate system. When both radii are same it is also possible to specify a single radius using the argument name r. The argument names are optional if the arguments are given in the same order as specified above. Parameters
cylinder(h = 10, r1 = 10, r2 = 20, center = false); cylinder(h = 10, r1 = 20, r2 = 10, center = true); cylinder(h = 10, r=20); cylinder(h = 10, r=20, $fs=6); [edit] polyhedronUsage example: polyhedron(points = [ [x, y, z], ... ], triangles = [ [p1, p2, p3..], ... ], convexity = N); Create a polyhedron with the specified points and triangles. (The 'pN' components of the triangles vector are 0-indexed references to the elements of the points vector.)
Real Example 1: polyhedron( points=[[0,0,0],[100,0,0],[0,100,0],[0,100,100]], triangles=[[0,1,2],[1,0,3],[0,2,3],[2,1,3]] ); Real example 2 (a kind of prism, see the picture below) polyhedron ( points = [[0, -10, 60], [0, 10, 60], [0, 10, 0], [0, -10, 0], [60, -10, 60], [60, 10, 60]], triangles = [[0,3,2], [0,2,1], [3,0,4], [1,2,5], [0,5,4], [0,1,5], [5,2,4], [4,2,3], ]); Note that if your polygons are not all oriented the same way OpenSCAD will either print an error or crash completely, so pay attention to the vertex ordering. e.g. polyhedron( points = [[0,0,0],[100,0,0],[0,100,0],[0,100,100]], triangles = [[0,1,2], [0,1,3], [0,2,3], [1,2,3]]); //Generates an error polyhedron( points = [[0,0,0],[100,0,0],[0,100,0],[0,100,100]], triangles = [[0,1,2], [1,0,3], [0,2,3], [2,1,3]]); //Works Let's now see how to fix polyhedrons with badly oriented polygons. When you select 'Thrown together' from the view menu and compile the design (not compile and render!) you will see a preview with the mis-oriented polygons highlighted. Unfortunately this highlighting is not possible in the OpenCSG preview mode because it would interfere with the way the OpenCSG preview mode is implemented.) Below you can see the code and the picture of such a problematic polyhedron, the bad polygons (triangles or compositions of triangles) are in pink. // Bad polyhedron polyhedron (points = [ [0, -10, 60], [0, 10, 60], [0, 10, 0], [0, -10, 0], [60, -10, 60], [60, 10, 60], [10, -10, 50], [10, 10, 50], [10, 10, 30], [10, -10, 30], [30, -10, 50], [30, 10, 50] ], triangles = [ [0,2,3], [0,1,2], [0,4,5], [0,5,1], [5,4,2], [2,4,3], [6,8,9], [6,7,8], [6,10,11], [6,11,7], [10,8,11], [10,9,8], [0,3,9], [9,0,6], [10,6, 0], [0,4,10], [3,9,10], [3,10,4], [1,7,11], [1,11,5], [1,7,8], [1,8,2], [2,8,11], [2,11,5] ] ); A correct polyhedron would be the following:
polyhedron
(points = [
[0, -10, 60], [0, 10, 60], [0, 10, 0], [0, -10, 0], [60, -10, 60], [60, 10, 60],
[10, -10, 50], [10, 10, 50], [10, 10, 30], [10, -10, 30], [30, -10, 50], [30, 10, 50]
],
triangles = [
[0,3,2], [0,2,1], [4,0,5], [5,0,1], [5,2,4], [4,2,3],
[6,8,9], [6,7,8], [6,10,11],[6,11,7], [10,8,11],
[10,9,8], [3,0,9], [9,0,6], [10,6, 0],[0,4,10],
[3,9,10], [3,10,4], [1,7,11], [1,11,5], [1,8,7],
[2,8,1], [8,2,11], [5,11,2]
]
);
Beginner's tip: If you don't really understand "orientation", try to identify the mis-oriented pink triangles and then permute the references to the points vectors until you get it right. E.g. in the above example, the third triangle ([0,4,5]) was wrong and we fixed it as [4,0,5]. In addition, you may select "Show Edges" from the "View Menu", print a screen capture and number both the points and the triangles. In our example, the points are annotated in black and the triangles in blue. Turn the object around and make a second copy from the back if needed. This way you can keep track. Clockwise Technique: (Noob entry, please confirm) Orientation is determined by clockwise indexing. This means that if you're looking at the triangle (in this case [4,0,5]) from the outside you'll see that the path is clockwise around the center of the face. The winding order [4,0,5] is clockwise and therefore good. The winding order [0,4,5] is counter-clockwise and therefore bad. Likewise, any other clockwise order of [4,0,5] works: [5,4,0] & [0,5,4] are good too. If you use the clockwise technique, you'll always have your faces outside (outside of OpenSCAD, other programs do use counter-clockwise as the outside though). [edit] TransformationsThe text in its current form is incomplete. [edit] scaleScales its child elements using the specified vector. The argument name is optional.
Usage Example:
scale(v = [x, y, z]) { ... }
[edit] rotateRotates its child a degrees about the origin of the coordinate system or around an arbitrary axis. The argument names are optional if the arguments are given in the same order as specified above. When a rotation is specified for multiple axis' the rotation is applied in the following order: x, y, z.
Usage:
rotate(a = deg, v = [x, y, z]) { ... }
For example, to flip an object upside-down, you might do this:
rotate(a=[0,180,0]) { ... }
The above example will rotate your object 180 degrees around the 'y' axis. The optional argument 'v' allows you to set an arbitrary axis about which the object will be rotated. Example with arbitrary origin.
rotate(a=45, v=[1,1,0]) { ... }
This example will rotate your object 45 degrees around the axis defined by the vector [1,1,0]. [edit] translateTranslates (moves) its child elements along the specified vector. The argument name is optional.
Usage example:
translate(v = [x, y, z]) { ... }
[edit] mirrorMirrors the child element on a plane through the origin. The argument to mirror() is the normal vector on that plane.
Usage example:
mirror([ 0, 1, 0 ]) { ... }
[edit] multmatrixMultiplies the geometry of all child elements with the given 4x4 transformation matrix. Usage: multmatrix(m = [...]) { ... } Example (translates by [10, 20, 30]):
multmatrix(m = [ [1, 0, 0, 10],
[0, 1, 0, 20],
[0, 0, 1, 30],
[0, 0, 0, 1]
]) cylinder();
Example (rotates by 45 degrees in XY plane and translates by [10,20,30]):
angle=45;
multmatrix(m = [ [cos(angle), -sin(angle), 0, 10],
[sin(angle), cos(angle), 0, 20],
[0, 0, 1, 30],
[0, 0, 0, 1]
]) union() {
cylinder(r=10.0,h=10,center=false);
cube(size=[10,10,10],center=false);
}
[edit] colorDisplays the child elements using the specified RGB color + alpha value. This is only used for the OpenCSG and Thrown Together display modes. The alpha value will default to 1.0 (opaque) if not specified.
Usage example:
color([r, g, b, a]) { ... }
Note that the r, g, b, a values are limited to floating point values in the range { 0.0 ... 1.0 } rather than the more traditional integers { 0 ... 255 }. However you can specify the values as fractions, e.g. for R,G,B integers in {0 ... 255} you can use:
color([ R/255, G/255, B/255 ]) { ... }
As of the 2011.12 version, colors can also be chosen by name. For example, to create a red sphere, you can use this code:
color("red") sphere(5);
Alpha is also available with named colors:
color("Blue",0.5) cube(5);
The available color names are taken from the World Wide Web consortium's SVG color list. A chart of the color names is as follows:
Chart based on "Web Colors" from Wikipedia [edit] minkowskiDisplays the minkowski sum of child nodes. Usage example: Say you have a flat box, and you want a rounded edge. There are many ways to do this, but minkowski is very elegant. Take your box, and a cylinder: $fn=50; cube([10,10,1]); cylinder(r=2,h=1); Then, do a minkowski sum of them:
$fn=50;
minkowski()
{
cube([10,10,1]);
cylinder(r=2,h=1);
}
[edit] hullDisplays the convex hull of child nodes. Usage example:
hull() {
translate([15,10,0]) circle(10);
circle(10);
}
[edit] CSG ModelingThe text in its current form is incomplete. [edit] unionCreates a union of all its child nodes. This is the sum of all children.
Usage example:
union() {
cylinder (h = 4, r=1, center = true, $fn=100);
rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
}
[edit] differenceSubtracts the 2nd (and all further) child nodes from the first one.
Usage example:
difference() {
cylinder (h = 4, r=1, center = true, $fn=100);
rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
}
[edit] intersectionCreates the intersection of all child nodes. This keeps the overlapping portion
Usage example:
intersection() {
cylinder (h = 4, r=1, center = true, $fn=100);
rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
}
[edit] renderAlways calculate the CSG model for this tree (even in OpenCSG preview mode). The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate. This parameter is only needed for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering.
Usage example:
render(convexity = 1) { ... }
[edit] Modifier CharactersThe text in its current form is incomplete. [edit] Background ModifierIgnore this subtree for the normal rendering process and draw it in transparent gray (all transformations are still applied to the nodes in this tree).
Usage example:
% { ... }
Example code: difference() { // start objects cylinder (h = 4, r=1, center = true, $fn=100); // first object that will subtracted % rotate ([90,0,0]) cylinder (h = 4, r=0.3, center = true, $fn=100); // second object that will be subtracted % rotate ([0,90,0]) cylinder (h = 4, r=0.9, center = true, $fn=100); } [edit] Debug ModifierUse this subtree as usual in the rendering process but also draw it unmodified in transparent pink.
Usage example:
# { ... }
Example: difference() { // start objects cylinder (h = 4, r=1, center = true, $fn=100); // first object that will subtracted # rotate ([90,0,0]) cylinder (h = 4, r=0.3, center = true, $fn=100); // second object that will be subtracted # rotate ([0,90,0]) cylinder (h = 4, r=0.9, center = true, $fn=100); } [edit] Root ModifierIgnore the rest of the design and use this subtree as design root.
Usage example:
! { ... }
[edit] Disable ModifierSimply ignore this entire subtree.
Usage example:
* { ... }
[edit] ModulesDefining your own module (roughly comparable to a macro or a function in other languages) is a powerful way to reuse procedures.
In this example, passing in the parameters distance, rot, and size allow you to reuse this functionality multiple times, saving many lines of code and rendering your program much easier to read. You can instantiate the module by passing values (or formulas) for the parameters just like a C function call:
The child nodes of the module instantiation can be accessed using the child() statement within the module:
If you need to make your module iterate over all children you will need to make use of the $children variable, e.g.:
module elongate() {
for (i = [0 : $children-1])
scale([10 , 1, 1 ]) child(i);
}
elongate() { sphere(30); cube([10,10,10]); cylinder(r=10,h=50); }
[edit] Include StatementThe text in its current form is incomplete.
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. [edit] Other Language FeaturesThe text in its current form is incomplete. [edit] Special variablesAll variables starting with a '$' are special variables. The semantic is similar to the special variables in lisp: they have dynamic instead of lexical scoping. [edit] $fa, $fs and $fnThe $fa, $fs and $fn special variables control the number of facets used to generate an arc: $fa is the minimum angle for a fragment. Even a huge circle does not have more fragments than 360 divided by this number. The default value is 12 (i.e. 30 fragments for a full circle). The minimum allowed value is 0.01. Any attempt to set a lower value will cause a warning. $fs is the minimum size of a fragment. Because of this variable very small circles have a smaller number of fragments than specified using $fa. The default value is 2. The minimum allowed value is 0.01. Any attempt to set a lower value will cause a warning. $fn is usually 0. When this variable has a value greater than zero, the other two variables are ignored and full circle is rendered using this number of fragments. The default value is 0. When $fa and $fs are used to determine the number of fragments for a circle, then OpenSCAD will never use less than 5 fragments. This is the C code that calculates the number of fragments in a circle:
int get_fragments_from_r(double r, double fn, double fs, double fa)
{
if (fn > 0.0)
return (int)fn;
return (int)ceil(fmax(fmin(360.0 / fa, r*2*M_PI / fs), 5));
}
Spheres are first sliced into as many slices as the number of fragments being used to render a circle of the sphere's radius, and then every slice is rendered into as many fragments as are needed for the slice radius. You might have recognized already that the pole of a sphere is usually a pentagon. This is why. The number of fragments for a cylinder is determined using the greater of the two radii. The method is also used when rendering circles and arcs from DXF files. You can generate high resolution spheres by resetting the $fX values in the instantiating module:
$fs = 0.01;
sphere(2);
or simply by passing the special variable as parameter:
sphere(2, $fs = 0.01);
You can even scale the special variable instead of resetting it:
sphere(2, $fs = $fs * 0.01);
[edit] $tThe $t variable is used for animation. If you enable the animation frame with view->animate and give a value for "FPS" and "Steps", the "Time" field shows the current value of $t. With this information in mind, you can animate your design. The design is recompiled every 1/"FPS" seconds with $t incremented by 1/"Steps" for "Steps" times, ending at either $t=1 or $t=1-1/steps. If "Dump Pictures" is checked, then images will be created in the same directory as the .scad file, using the following $t values, and saved in the following files:
Or, for other values of Steps, it follows this pattern:
Which pattern it chooses appears to be an unpredictable, but consistent, function of Steps. For example, when Steps=4, it follows the first pattern, and outputs a total of 4 files. When Steps=3, it follows the second pattern, and also outputs 4 files. It will always output either Steps or Steps+1 files, though it may not be predictable which. When finished, it will wrap around and recreate each of the files, looping through and recreating them forever. [edit] User-Defined FunctionsDefine a function for code readability and re-use. Usage examples:
my_d=20;
function r_from_dia(my_d) = my_d / 2;
echo("Diameter ", my_d, " is radius ", r_from_dia(my_d));
[edit] Echo StatementsThis function prints the contents to the compilation window. Useful for debugging code. Usage examples:
my_h=50;
my_r=100;
echo("This is a cylinder with h=", my_h, " and r=", my_r);
cylinder(h=my_h, r=my_r);
[edit] RenderForces the generation of a mesh even in preview mode. Useful when the boolean operations become too slow to track. Needs description. Usage examples:
render(convexity = 2) difference() {
cube([20, 20, 150], center = true);
translate([-10, -10, 0])
cylinder(h = 80, r = 10, center = true);
translate([-10, -10, +40])
sphere(r = 10);
translate([-10, -10, -40])
sphere(r = 10);
}
[edit] SurfaceExample 1: //surface.scad surface(file = "surface.dat", center = true, convexity = 5); %translate([0,0,5])cube([10,10,10], center =true); #surface.dat 10 9 8 7 6 5 5 5 5 5 9 8 7 6 6 4 3 2 1 0 8 7 6 6 4 3 2 1 0 0 7 6 6 4 3 2 1 0 0 0 6 6 4 3 2 1 1 0 0 0 6 6 3 2 1 1 1 0 0 0 6 6 2 1 1 1 1 0 0 0 6 6 1 0 0 0 0 0 0 0 3 1 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 Result: Example 2
// example010.dat generated using octave:
// d = (sin(1:0.2:10)' * cos(1:0.2:10)) * 10;
// save("example010.dat", "d");
intersection() {
surface(file = "example010.dat", center = true, convexity = 5);
rotate(45, [0, 0, 1]) surface(file = "example010.dat", center = true, convexity = 5);
}
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This page may need to be 






