Openscad Examples

From Hackerspace Brussels
Jump to: navigation, search

Making 3 cones[edit]

This example will produce 3 solid cones that look like this:


The code comprises:

  • global variable definitions
  • module ,i.e. procedure definitions
  • calls to the procedures to execute the model.

Global Variables[edit]

// cone construction defs
// a cone is a cylinder with 2 radii, upper and lower
r_lower= 20;

// the next var determines how 'smooth' the curves will be, 
// i.e. the number of faces, all openscad objects can take this

// cone placement defs
// these variables are used to grow and place the cones
cone_step= 2*r_lower;


Modules are callable procedures. We will define 2 of them:

  • The first makes a single cone and places it at the origin of the coordinate system [0,0,0]
  • the second calls the first nb times, making cones and translating (moving) them along the x-axis.
// this makes a single cone of 'height' tall,
// at [0,0,0]
module cone(height){
           $fn=definition);   // the 'smoothness'

// this makes 'nb' cones,
// each is taller than the previous,
// while shifting them along the x-axis
// note:this code will not make proper STL, because of 'holes' between the cones

module make_cones(nb){
  for (i= [0:nb-1]){

The Work-Horse Code[edit]

// this does the work

Using this in OpenScad[edit]

  1. First download the File:3conesExampleCode.txt but save it as 3cones.scad.
  2. Load it into Openscad
  3. Hit F5 to visualize the result. You should see the 3 cones.
  4. Hit F6 to compile, and see if your object is ok to become a.STL file. You will see that it is NOT ok because "simple" is "no"
Top Level object is a 3D object.
Simple:   no

To make it simple you have to reduce the cone_step so there is overlap, for example:

cone_step = r_lower-0.1;

Hope this helps someone!