How to use a parametric file

This article’s goal is to explain how to use a parametric file with OpenScad, to produce a made-to-measure object. You don’t need any knowledge concerning 3D or programming to follow what is described here. But if you want to learn how to create parametric files, you can refer to OpenScad documentation.

 

  • WHAT’S A PARAMETRIC FILE ?

A parametric file is a “flexible” 3D model. It is a 3D model which is only made by combining simple volumes, expressed as geometry (CSG modeling). It provides the user ability to use parameters, and to choose which values are associated with each parameter, to make a customized object. A parametric file could potentially produce an almost infinite quantity of different models.

Parametric files are particularly useful with 3D printing, since they can produce customized items, which may for example be adapted to existing supplies, or used as a spare. One could also print a prototype, verify the effectiveness of chosen values in real situations and easily adjust and print again …

For example, the pictures below is an overview of parametric file “Highly Configurable Wheel” that allows creation of customized wheels (coded by Alex Franke – CodeCreations, you can download it here : http://www.thingiverse.com/thing:21486).

Here we see the possible values for the “spokeStyle” parameter:

HCW-SpokeStyles1

And here’s how this parameter will be affected by other parameters :

HCW-SpokeStyles2

 

  • WHERE TO FIND PARAMETRIC FILES ?

You can download parametric files on 3D files sharing platforms: Thingiverse, Youmagine, Cults

To find them, use “customizable” or “parametric” keywords in the search bar of these websites, in addition to the type of object you are looking for. For example, to find a parametric box, you can search “customizable box” or “parametric box”.

If you find something that seems to suit you, check that you have access to a SCAD file (whose name ends with the extension “.scad”), if so, download it.

Thingiverse website provides a graphical interface online, facilitating the use of parametric files, called “Customizer”. If a SCAD file is available, an “Open in Customizer” button (proposing to open the file in the “Customizer”) appear on the page.
 

  • HOW TO CUSTOMIZE A PARAMETRIC FILE ?

This article discusses about SCAD files, to use them you must install OpenScad software. It is free, open source, and available for Windows, Mac and Linux. You can download the version for your operating system here: http://www.openscad.org/downloads.html

Once OpenScad installed on your computer, launch it.
At the opening, a window lets you directly open a file, or create a new one. You can also open it conventionally, via the menu bar (File / Open).

 

1/ INTERFACE

This is how a file looks like in OpenSCAD (below, “Customizable Knob!”, coded by Charliearmorycom, allowing user to create customized knobs. You can download it here : http://www.thingiverse.com/thing:54024) :

customizableKnob-openScad

The interface is divided into 3 areas:

sergePayen-OStuto-interface

– The editor : the left column, where the code (the computer language defining the 3D model) is written, and where you will also find the different parameters and their values. A parametric file being only textual, this is the most important part of the OpenSCAD interface.

– The viewing area : at editor’s right, its only purpose is to see the object being worked on. Unlike most 3D modeling software, in OpenSCAD no action is done “visually”. Everything happens in the editor, as code (text). The viewing area is only indicative, to look at the result of changes made in the editor. Inside, you can “orbit” around the object (move the mouse while holding down the left mouse click), move (move the mouse while holding down the right mouse button), or zoom in-zoom out (mouse scroll wheel).
Below, there are these buttons:

openScad-viewsIcons

They correspond to the standard views (top, bottom, side …).

– The console : below the viewing area, it returns information about the object, and also lets you debug a file, indicating which line of code is a potential problem.

 

Close-up on the editor :

sergePayen-OStuto-editor

We see the available settings (written in black) and their default values (written in dark red). These are the values that can be changed to customize the model. The blue-green texts are comments (see below).

Usually, the code’s part including parameters and their values is at the beginning (editor’s top), often after a few lines of information (file’s title and author, license …).

 

2 / PARAMETERS, VALUES AND COMMENTS

In OpenScad language, a parameter and its value are written like this:

parameter = value ;

(The semicolon at the end of the expression is important, do not delete it by mistake. Generally, be careful to change only the values, and nothing else).

Comments are small texts to help the user. They provide guidance on the use of the file or settings. Comments are preceded by “//” (double slash), or enclosed between “/*” (slash star) and “*/” (star slash), to differentiate from the code.

The image below shows an example of comment (circled in blue), setting (circled in red) and value (circled in orange) :

sergePayen-OStuto-parameters

“Hole Diameter” parameter’s default value is “6”, and it is preceded by a comment indicating that this is about adjusting the diameter (in mm) of knob’s bottom’s hole.

To customize this file, just change the values corresponding to the parameters you’re interested in. This is the effect of a change of values for the parameters “Knob Height” and “KnobDiameter” (knob’s height and diameter, in mm):

sergePayen-OStuto-numeric1

sergePayen-OStuto-numeric2

At first, the knob was “20” mm height for “20” mm width. By simply changing these values by the numbers “15” and “100”, we obtained a 15mm height knob, for 100mm width. Once preview is generated, you can see the new model.

 

3/ VIEWING CHANGES : THE PREVIEW

After changing one or more values in the code editor, you need to tell OpenSCAD that you want to generate an overview of the model with the new values you indicated.

To generate the preview:

Press F5 key on the keyboard.

Or this button in the interface : openScad-compileIcon

Or via the menu bar (Design / Compile).

So we can, at will, change the value of any parameter of our choice, view the result with the preview, if necessary, adjust the values again, visualize with the preview, etc …

 

4/ NON NUMERICAL VALUES

In the example above (knob’s height and diameter), we changed numerical values, which are the most common.

The other main type of value is called “boolean”. There are only two boolean values: TRUE (it’s like “yes”) and FALSE (it’s like “no”). Typically, boolean values are used to propose options. For example, let’s imagine a coffee cup file, this one could propose the setting “handle” that can be set to “true” (yes, I want a cup with a handle) or “false” (no, I want a simple cup without handle).

Here’s an example (with the “Parametric Lego Brick” file, created by Andrew Sweet, which produces custom Lego pieces. Downloadable here : http://www.thingiverse.com/thing:231651) :

sergePayen-OStuto-legoTrue

sergePayen-OStuto-legoFalse

For the “pegs” parameter, you can choose “true” or “false” values, it has the effect of producing a piece with Lego pegs on top (if “true”) or rather a flat Lego piece (if “false”).

 

Finally, there is one last type of values, those that have been predefined by the author of the file, often to offer a choice of several options. This may be numerical values such as “0, 1, 2, 3 …”, in this case the comments indicate what each option is about. This is what we see in the “Customizable Furniture Minis” file, by mathgrrl, which produces furniture mini-models (downloadable here: http://www.thingiverse.com/thing:332507) :

sergePayen-OStuto-furniture8

sergePayen-OStuto-furniture15

Selecting value “8” for the “custom furniture” parameter will produce a sofa bed, selecting value “15” will produce a tree. We find all matches in the comments next to the parameter.

 

The same kind of values can be expressed “literary”. This is the case in “Highly Configurable Wheel” file, presented at the beginning of this article, allowing user to create custom wheels.

sergePayen-OStuto-stringCircle

sergePayen-OStuto-stringLine

The parameter value is then like a “word” (more accurately a “string“, in computer-speaking). In this form, the value must be entered between double quotes. Again, possible options are usually included in the comments.

 

6/ GET A PRINTABLE STL FILE : RENDER AND EXPORT

Once obtained the desired object, which can be observed through the viewing area as a preview (as explained above), you must make a render, so the object is truly “built”.

To make the render :

Press F6 key on the keyboard.

Or this button in the interface : openScad-renderIcon

Or via the menu bar (Design / Compile and Render).

I changed the knob presented above to use it with the LCD controller of my printer, and I made the render :

sergePayen-OStuto-render

Rendering can take a while, and visually does not change much compare to what could be observed before in the viewing area (with the preview). But it is absolutely necessary to be able to export a model. And to send this file to a 3D printer, or open it in another program, you must export it as STL.

To perform a STL export :

Press this button in the interface : openScad-STLicon

Or via the menu bar (File / Export / Export as STL).

Give a name to your STL file.

Now you can print the object that you modified according to your needs… Here is my customized knob once printed :

sergePayen-OStuto-boutonPrint

And once installed on my LCD controller :

sergePayen-OStuto-boutonLCD

If you do not have a 3D printer, you can print your file in a FabLab, or pay “someone” to print it on 3DHubs, or via a service provider such as Sculpteo or Shapeways.