

If we now need to change the adjustment in our example again, then we only need to update the function adjust(x). We can do this by using a variable:įunction adjust(x) = (x + adjustment) * adjustment_factor However, if we want to make the radius of the sphere configurable in our model, then we should give the radius its own name. If we are sure that we will never need or want to adjust this value again, this is perfectly fine. So far we have specified the radius of our sphere with a concrete value. In this sense, the expression sphere(r=10) says something like: there exists a sphere with radius 10mm.

It is better to interpret the expression not as a method call, but rather as a statement about the existence of a concrete geometry. Unfortunately, in the context of OpenSCAD this intuition is more hindering than useful. If you have some programming experience, the expression sphere(r=10) may remind you of a method call. The order of the parameters does not matter here. So for the sphere, the diameter has priority over the radius if both are given. If you now run a preview ( F5), then the sphere does not change and a warning highlighted in yellow is displayed in the console: Ignoring radius variable ‘r’ as diameter ’d' is defined too. In the case of the sphere, the radius parameter has the name r and using this parameter name would look like this: Each parameter also has a name and in general it is better to include this name.

In the example above, the radius of the sphere is the first parameter. Maybe you mistyped? Or maybe you forgot the semicolon at the end of the line? Did you perhaps write sphere with a capital S instead of a small one? Try to find the mistake and run the preview ( F5) again.Įach basic shape in OpenSCAD has a unique name, which is always followed by a list of parameters in round brackets and a terminating semicolon. If instead there is a red marked ERROR in the console output, something went wrong (Figure 2. The second to last line of this output should contain the message Compile and preview finished. You should find a number of messages that were generated as part of the preview. : Successful rendering of the previewĪlso take a look at the console window. If you now run a preview ( F5), the output window should show a sphere with a radius of 10 millimeters. To do this, enter the following into the editor: These are two or three dimensional basic shapes that we can use as building blocks for our model. The basis of any geometry in OpenSCAD are so-called primitives. The OpenSCAD program window should show the internal editor, the output window and the console view. If you have not already done so, now would be a good time to start OpenSCAD with an empty or new file. Let’s start by describing our first geometry in OpenSCAD. An exhaustive description of all functions can be found at the end of the book as well as in the online documentation of OpenSCAD. The focus of this chapter lies on conveying the essential concepts and functionality of OpenSCAD using select examples. In the course of the following sections, this difference will become more apparent. Rather, it is the specification of a geometric structure. Although the textual description reminds of classical program code, it is not a program. Especially if you have some programming experience, this apparent similarity can lead to some misunderstandings and misguided intuitions. At first glance, this description resembles a program written in a programming language such as Javascript or C. As mentioned before, geometric models in OpenSCAD are described by a textual description.
