Seminar on "Parametric modeling with OpenSCAD" by Mitja

We will give an introduction to parametric modeling and design a few things with OpenSCAD.

## Basic Control

• type into the editor on the left
• whenever you are ready to compile your code to see it in the 3D preview on the right, you can click "preview" or hit F5
• group arguments with `{ ... }`
• group objects by applying `union()` to a group of arguments - important for CNC!
• subtract objects or groups of objects from each other with `difference()`
• everything is subtracted from the first object or union after this function
• `!` at the beginning of a line shows only that operation
• `#` at the beginning of a line shows that object as defined, e.g. also the superfluous parts of a hole

## First Steps

We start by defining a small cube (units in mm) with `cube([2,2,2]);`.

• center the cube by adding `center=true` after the vector, between ] and )
• translate (move) the cube by calling `translate([2,0,0])` - it will end up two mm further in positive X direction

After also tinkering with some spheres and cylinders (enter `\$fn=` followed by a number to define your desired face count, high numbers increase rendering time!), let's move on to parametric designs.

## Parametric Designs

We'll make an "L" with adjustable side lengths and a parametric hole.

The "L" is rather simple and consists of two "cubes" that are actually rectangles due to the entered values. By adding the global variable "edge_length", we can later change the dimensions of the entire letter while keeping its proportions:

```edge_length = 5;

union()
{
cube([1*edge_length,5*edge_length,1*edge_length]);
cube([3*edge_length,1*edge_length,1*edge_length]);
}
```

Then, we add a hole with a corresponding "hole_diameter" variable and turned the L into a module which can then be called similar to `cube` or `sphere` from the first examples:

```module L(edge_length, hole_diameter)
{
difference()
{
union()
{
cube([1*edge_length,5*edge_length,1*edge_length]);
cube([3*edge_length,1*edge_length,1*edge_length]);
}
translate([edge_length/2, edge_length/2, -1])
cylinder(r=hole_diameter/2, h=edge_length+2, \$fn=20); //sticks out 1 mm at top/bottom, "centered" in corner
}
}

L(4,1);
translate([15,0,0]) L(6,2);
```

The last two lines in this example create two "L" shapes with different sizes, one of which starts at the origin while the other is moved 15 mm in X direction.