How to open .stl file and the program OpenSCAD

Abbreviation STL stand for STereoLithography (Stereolithography is a technology for 3D printed objects creation). Files with .stl extension are stored 3D model of objects, they can be "printed" using 3D printer. There are two types of .stl files - binary and text (ASCII). Binary files are more compact, text .stl files can be edited with a text editor.

One of program that open .stl file format is free OpenSCAD (Solid 3D CAD Modeller), it can be downloaded from this site: http://www.openscad.org (there are Windows/Mac OS X/Linux/BSD versions).

How to open an .stl file using this program? Select File --> Open from the main menu, or press CTRL+O hotkeys. Enter file mask *.stl in the Open File dialog as it shown in the screenshot below:

Open File Dialog with .stl file mask in the Solid 3D CAD Modeller program

That allows to see all .stl files in the current directory, select a file and open it. Another way to open .stl file is to use drag and drop method - just drag a file from Windows Explorer and drop in on the OpenSCAD program.

The main window of OpenSCAD program consists of three fields: the text editor field at left, the graphic field at top right, and the console output area at the bottom right that shows messages. The status bar is located at the very bottom of the window. It shows the progress indicator if compiling and visualization are in progress.

Main window of OpenSCAD shows a rendering model

After the file is open, it can be compiled. Hit F5 (Preview) or F6 (Render). Use mouse to rotate the model (hold left mouse button pressed) or move it (hold right mouse button). Use menu "View" to select a point of view and move model to the screen center.

The program OpenSCAD allows to export 3D models into .STL, .OFF, .DXF, .CSG formats, and export into image format .PNG (main menu --> Design). For .STL, .OFF and .DXF formats a model must be compiled and visualized before exporting by pressing F6. For .CSG it takes only to compile the model (hit F5 key).

An example of exporting of 3D model into a graphic PNG file is shown on the picture below:

3D model in the program OpenSCAD

The program OpenSCAD allows to create solid 3D models. A model describes with a simple scripting language. Here is an example how to create a sphere with holes:

  1. $fn = 100;
  2. difference()
  3. {
  4. color([0, 1, 1])
  5. sphere(40, center = true);
  6. color([1, 1, 0.9])
  7. cylinder(150,30,30, center = true );
  8. rotate(90, [1, -0.66, 0]) cylinder(150,10,10, center = true);
  9. rotate(90, [1, 0.66, 0]) cylinder(150,10,10, center = true);
  10. rotate(90, [0, 1, 0]) cylinder(150,10,10, center = true);
  11. }

Let's see what is in this code. A system variable $fn determines number of polygons of the model, that means it determines graphic resolution (quality) of rendering. For example, if set $fn = 10, the model will look very edgy, just like this:

Very edgy 3D model

The parameter $fn can be set separately for every object, as it shown in this example:
sphere(20, center = true, $fn = 300);

With higher value of $fn parameter the program produces more polygons, therefore the surface will looks much smoother, but it takes more time to compile a model.

The next line with a logical operator difference(), it subtracts the first figure or figures (cylinders - lines 7..10) from the second one (the sphere - line 5). Cylinders are subtracting from the sphere. By the way, there are two other logical operators - union() and intersection(). All those operators are working with multiple figures, so all the figures must be enclosed inside curly brackets {}.

Thus, the program OpenSCAD allows to provide three logical (Boolean) operations over 3D objects:

The operator color([0, 1, 1]) changes the color (RGB) of an object in decimal units, the range is from 0.0 to 1.0. It also can use the fourth parameter, it determines transparency.

Example: color([0, 1, 1, 0.3])

Instead of numbers, colors can be defined by names.

Example: color("red"))

This operator affects the next to "color" object.

Example: color("blue") sphere(20, center = true, $fn = 300);)

To change color of several objects, it takes to enclose them into curly brackets (just like in C++ programming language).

Example:

color("lime")
{
sphere(20, center = true, $fn = 300);
cylinder(30,10,10);
}

The next operator sphere(40, center = true); (the line 5) creates a sphere with radius of 40, the sphere's center matches the center of coordinate system (center = true). Axes of the coordinate system can be turned on or off by using the hotkey Ctrl+2 or use the main menu of the program View --> Show Axes.

Another operator color([1, 1, 0.9]) determines the color of the big cylinder (cylinder(150,30,30, center = true );). After the operation is completed, the inner surface of the cylinder gets gray color.

At the and, three operators create cylinders. The operator rotate rotates each of the cylinder.

This is the list of 3D objects of OpenSCAD:

Except from Boolean operation, the program OpenSCAD provides a linear extrusion operation - this operation turns 2D primitives into 3D objects, just like SolidWorks program does. An example:

linear_extrude(10) polygon([[0,0],[0,20], [20,20],[10,10],[20,0]]);

In this example a flat 2D object consisted of 5 points in X plane is created with the command polygon, then it extrudes with linear_extrude command along Z axis. Here is the result of that operation:

Linear Extruding 2D shape into 3D Object in OpenSCAD

This is the list of 3D objects that can be extruded in OpenSCAD program:

A text example:

$fn = 100;
color([0, 1, 0])
linear_extrude(10) 
{
 text("http://zpostbox.ru", font="Arial");
}

linear text extruding in OpenSCAD

As can be seen from the above, the program allows to create 3D objects of any complexity.

BACK