Introduction: 3D Models With OpenSCAD

In this tutorial, I'm going to show you how to use OpenSCAD to produce a simple 3D model by extruding a part profile produced in normal drawing software. I use Adobe Illustrator CS3 because I have access to it and am familiar with its interface, but the popular freeware drawing program InkScape will read and write DXF files natively, and there's no reason why it couldn't serve just as well if you prefer it

Step 1: Materials

Computer
Drawing software
OpenSCAD

Step 2: Step 1 €” Size Art Board Appropriately

Sizing the page or art board to exactly the size of your finished part will make it easier to view the rendered extrusion in OpenSCAD. The zero coordinate seems to be determined based on one corner of the art board, and if you draw a 1.5" x 1.5" part in the middle of a letter-sized page, the actual model tends to end up out off the edge of the screen when you render it. Save yourself the nuisance and shrink the art board down when you first create the new drawing.

Step 3: Step 2 €” Draw Grid in Bottom Layer

A grid or any other drawing guides you may want to include should be drawn first, in a separate layer.

In the case of the rabbit pentomino, the animal profile needs to fit into the outline of the normal "Z" pentomino, which is five squares simply joined as shown.

These puzzle pieces are designed on a 0.5" grid, so start by drawing a single 0.5" square using the box tool. Then make a copy of that square, paste it, and use the arrow tool to snap its corners to the corners of the original square. Then repeat the copy-paste-snap process to add the remaining three squares in their proper positions. Then "select all" and change the stroke color to something other than black to make it easy to distinguish part lines from grid lines later on.

Finally, lock the layer and create a new one to draw the actual part lines in. Change the stroke color back to black.

Step 4: Step 3 €” Draw Profile Without Using Splines or Polylines

The DXF importer in OpenSCAD is based on AutoCAD's DXF revision 12 (R12) file specification, which does not include some of the more advanced drawing elements included in revisions 13 and later. Most notably, these are the POLYLINE and SPLINE elements.

It is doubtlessly not an accident that my version of Illustrator (CS3) only exports DXFs revision 13 and later, but these seem to be backwards-compatible with R12 as long as you avoid using certain drawing tools, notably compound paths. Put simply, each line in the drawing has to be a separate line segment with its endpoints unjoined. The box and ellipse tools seem to work, also.

Make sure that snapping is turned on, and that the beginning of each line segment is snapped exactly to the endpoint of the preceding line segment. Otherwise your part profile will have openings and will not render correctly. If you screw up and include an unsupported drawing element or create a non-closed part profile, you'll get a warning later when OpenSCAD tries to render the model.

Step 5: Step 4 €” Delete Grid Layer

When you've got the profile drawn to your satisfaction, save your drawing in its native format (.AI in the case of Illustrator).

Then select the bottom layer containing the grid or other drawing guides and delete it, leaving only your part profile in the drawing's single remaining layer.

Step 6: Step 5 €” Export As DXF

If you have the option to export in DXF R12, use it.

In Illustrator CS3, just use the default DXF export options.

Step 7: Step 6 €” Import DXF File Into OpenSCAD

Launch OpenSCAD, then enter (or copy-paste) the following code into the new document:

dxf_linear_extrude(file = "rabbit-Z.dxf", height = 12.7, center = true, convexity=1);

"file" is the name of the DXF file you want to import, "height" is the height in millimeters you want to extrude the profile (12.7 mm = 0.5"), "center" is a Boolean variable that tells OpenSCAD whether to center the rendered model or not (I've never really messed with it), and "convexity" is a scalar representing the fineness with which to render curved surfaces. Given that my part profiles contain almost no curved surfaces, I was happy with the minimum convexity of 1. If your parts are curvier than mine you may want to raise it.

Save the OpenSCAD script as a .SCAD file with an appropriate name.

Step 8: Step 7 €” Compile and Render Model

From the drop-down menus select "Design > Compile and render (CGAL)" or just press F6.

If you've done everything right, your extruded part should appear in the render window in the upper-right corner of the workspace, as shown.

You can rotate it around by left-clicking and dragging the mouse, pan the camera by right-clicking and dragging, and zoom in and out with the scroll wheel.

If the DXF file contains open paths or unsupported drawing elements, you will see corresponding error messages in the log window at the lower right. You may have to scroll up to see them. For whatever reason, even though you have produced only a single part, OpenSCAD will probably report that you have 2 volumes in your rendered model. This may or may not be a bug; in any case, it doesn't seem to hurt anything so don't worry about it.

Step 9: Step 8 €” Export Model As STL File

From the drop-down menus, select "Design > Export as STL...", choose an appropriate filename, and click "Save."

OpenSCAD should report "STL export finished" in the log window. And that's it! Your 3D model should be ready for printing or import into a compatible 3D WYSIWYG modeler like Blender.