OpenSCAD OpenSCAD is a free software for creating solid 3D CAD objects. It is available for Linux/UNIX, MS Windows and Mac OS X. About OpenSCAD Open SCAD is focused on the CAD (Computer Aided Design) aspects of creating 3D models. Other programs (such as Blender) are more concentrated on the artistics aspects of this process. Thus, it might be the application you are looking for when you are planning to create 3D models of machine parts. OpenSCAD is not an interactive modeller. Instead it is something like a 3D-compiler that reads in a script file that describes the object and renders the 3D model from this script file. This gives you (the designer) full control over the modelling process and enables you to easily change any step in the modelling process or make designs that are defined by configurable parameters. OpenSCAD provides two main modelling techniques: First there is constructive solid geometry (aka CSG) and second there is extrusion of 2D outlines. As data exchange format for this 2D outlines Autocad DXF files are used. In addition to 2D paths for extrusion it is also possible to read design parameters from DXF files. Besides DXF files OpenSCAD can read and create 3D models in the STL and OFF file formats.
The OpenSCAD Interface The user interface of OpenSCAD has three parts The viewing area The console window The text editor Viewing area Preview and rendering output goes into the viewing area. Using the Show Axes menu entry an indicator for the coordinate axes can be enabled. Console window Status information, warnings and errors are displayed in the console window. Text editor The built-in text editor provides basic editing features like text search & replace and also supports syntax highlighting. There are predefined color schemes which can be selected in the Preferences dialog.
Example 1: Create a simple cuboid First Steps in OpenSCAD In the editor window write: cube ([3,3,3]); Then press F5 to compile and render the cube Example 2: Positioning and object Here we are going to use the translate positioning command to place an identical cuboid next to the cuboid we have already created in example 1 In the editor window write: cube ([3,3,3]); translate ([5,0,0]){ cube ([3,3,3]); Press F5 Notice that there is NO semicolon under the translate function Notice that curly brackets { are a part of the translate function Example 3: Changing the color of an object Colors in OpenSCAD is based in the RGB mode (Red, Green, Blue) Note: the range of Red, Green and Blue changes from 0.0 to 1.0 instead of 0 to 255. We are going to draw 3 cubes in 3 different colors: red, green and blue. In the editor window write: color ([1,0,0]) cube ([3,3,3]); translate ([3,0,0]) color ([0,1,0]) cube ([3,3,3]); translate ([6,0,0]) color ([0,0,1]) cube ([3,3,3]); Press F5 to compile and render the result
Example 4: Draw a sphere Spheres are always drawn centred at the origin of the coordinate system. The radius or the diameter can be used as a parameter: sphere(radius) or sphere(diameter). Resolution can be added with the $fn parameter. Be careful: high n values slow down the generation of the model. In the editor window, write: sphere (r=5); sphere (9); sphere(d=12); sphere (5, $fn=20); sphere (9, $fn=40); sphere (12, $fn=80); Press F5 to render the result. Example 5: Draw cylinders and cones Cylinders and Cones use the same instruction. The only difference is that for the cylinder we write one radius, and for the cone we write two radius. The instruction format is cylinder (height, r1, r2, center). Diameters and the modifiers $fn. $fa and $fs for circumferences can also be used. In the editor window, write: cylinder (h=15, r1=20, r2=10, center = false); Press F5 to render the model, and then: a) Change the values of the center to true. What happens? b) Exchange the values of r1 and r2. What s the result? c) Now write cylinder (h = 15, r = 20); What figures appears? d) Add the parameter $fn=6. What s the new figure?
More examples in OpenSCAD Example 6: Union of two cylinders union() { cylinder (h = 4, r=1, center = true, $fn=100); rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100); Example 7: Difference of two cylinders difference() { cylinder (h = 4, r=1, center = true, $fn=100); rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
Example 8: Intersection of two cylinders intersection() { cylinder (h = 4, r=1, center = true, $fn=100); rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100); Example 9: Union, Difference and Intersection of two cuboids This is an advanced example for you to TRY the code for examples 6, 7 and 8 with a cuboid instead of a cylinder. Example 10: Creating a simple keyholder $fn = 20; difference () { hull () { # translate([0,0,0]) cylinder(r=2,h=3); translate([10,0,0]) cylinder(r=2,h=3); translate([5,40,0]) cylinder(r=4,h=3); translate([5,38,-1]) cylinder(r=1,h=5);