mbugert / laserscad

A library for efficient lasercutting with OpenSCAD.
GNU Lesser General Public License v3.0
49 stars 10 forks source link
3d-models laser-cutting lasercut openscad openscad-library

laserscad 0.3.2

A library for efficient lasercutting with OpenSCAD.

Dominoes modelled using laserscad

Key Features

Installation

You will need:

To set up the library:

Tutorial / Code Example

The library is best explained with an example (click here to jump to the full API reference).

Say we want to create this small table which consists of a table top and two legs:

Small table cut from 5mm MDF

Creating the Model

Let's start by including laserscad and by defining some lengths and a basic table top:

include <laserscad.scad>

thick = 5; // 5mm thick material
top_x = 80;
top_y = 50;
leg_y = 40;
leg_z = 30;

cube([top_x, top_y, thick]);

We need to inform laserscad that our cube should be a lasered part. To do so, we wrap it with lpart(), which takes two arguments: a globally unique string identifying this part and its dimensions on the x and y axes:

lpart("table-top", [top_x, top_y]) {
    cube([top_x, top_y, thick]);
}

Let's translate the table top to where it will sit in the final model. Lparts can be translated using ltranslate, which basically behaves like the ordinary translate operator:

ltranslate([0,0,leg_z-thick]) {
    lpart("table-top", [top_x, top_y]) {
        cube([top_x, top_y, thick]);
    }
}

Here's what it looks like in OpenSCAD now:

Table top floating in the air

Next, we create a reusable module with more complex geometry for the table legs. We will instantiate two instances of this model in a moment:

module leg(id) {
    lrotate([0,-90,0])
        lpart(str("table-leg-",id), [leg_z, leg_y])
            difference() {
                cube([leg_z, leg_y, thick]);
                translate([0, leg_y/2, 0]) {
                    cylinder(r=leg_y/4, h=thick);
                    translate([leg_z, 0, 0])
                        cylinder(r=leg_y/4, h=thick);
                }
            }
}

There are two more things to point out on this code snippet:

If we instantiate a leg with leg("left"); it will look like this:

Table leg with two cutouts

What's left to do now is to instantiate and position the two legs and to modify our table top so that it features cutouts for the legs. Afterwards, the model looks like this in 3D:

Table with two legs, assembled

The full code for the example can be found at example/table.scad.

Generating the 2D laser template

Say we saved the model to the file ~/table.scad. To generate the lasercutting template, we open a shell in the folder containing Makefile and run make model=~/table.scad. This creates the file ~/table.dxf which contains the template for our table:

Lasercutting template for the table

There will also be a folder ~/_laserscad_temp which, once we have the DXF file, can be removed manually or by calling make clean model=~/table.scad.

API Reference / Function Overview

This section covers modules/operators offered by laserscad and parameters related to lasercutting.

Including the library

include <laserscad.scad>

lpart

Defines a single object which will be lasercut, consisting of its children. Children must be located in the first octant (in the positive x,y,z range). laserscad projects lparts on the xy-plane, i.e. lparts should be modeled as 3D objects lying on the xy-plane with a thickness in positive z-direction.

lpart(id, [x, y]) { ... }

Parameters

ltranslate

Use ltranslate to translate lparts. Has the same method signature as the regular translate. To move things around inside of lpart, use the regular translate.

lrotate, lmirror

Similar to ltranslate.

ldummy

Children of ldummy are shown during development but are ignored when exporting 2D templates. This can be useful for modeling laser-cut parts around reference objects.

lengrave

Engraves its children onto its parent lpart. To elaborate on this: lengrave must be used inside of lpart. What is being engraved is defined by the children of lengrave, which can be simple shapes, text, some imported DXF, etc.

lengrave(parent_thick, children_are_2d) { ... }

Parameters

Example

See docs/examples/engraving.scad.

Picture of a pattern engraved on an MDF sheet

lslice

Children of lslice are sliced along the z-axis with a specifiable slice thickness. This creates multiple lparts at once. Children must be located in the first octant (in the positive x,y,z range).

lslice(id, [x, y], z, thickness) { ... }

Parameters

Example

See docs/examples/slicing.scad. lslice demonstration Low Poly Stanford Bunny by johnny6 is licensed under the Creative Commons - Attribution - Non-Commercial license.

lassert_version

laserscad uses semantic versioning. With lassert_version, one can specify the laserscad version required by a model. This is a bonus feature. It is not necessary to use lassert_version, but it can help to keep one's projects organized.

lassert_version(major=..., minor=...);

Parameters

Examples

Other laserscad Parameters

Advanced features of laserscad can be enabled by specifying these parameters anywhere in the global scope of a scad file.

A note about OpenSCAD models consisting of multiple files: These parameter definitions have to find their way into every file where lpart is used. The easiest solution to this is to specify the parameters in some settings.scad file which is imported in everywhere via include <settings.scad>.

lkerf

Compensate kerf (shrinkage caused by the laser beam) for all lparts in millimeters. Default = 0

lmargin

Distance between lparts in the 2D template in millimeters. Default = 2

lidentify

Assembling models with many similar-looking lparts can be a challenge. If the boolean lidentify parameter is set to true, each lpart will be engraved with its unique id, eliminating any confusion. Default = false

Exporting 2D templates

This is a reference of the commands for exporting a template for lasercutting or for engravings.

Lasercutting template

Open a shell and run:

cd laserscad/dist
make cut model=path/to/your/model.scad

The path can be a relative or absolute path pointing to the OpenSCAD model you want to export. This creates a lasercutting template as a DXF file in the same folder as your model.

Engravings

cd laserscad/dist
make engrave model=path/to/your/model.scad

This creates an SVG file with the engravings in the same folder as your model.

Hint: To export the lasercutting template and the engravings in one go, run: make -j 2 cut engrave model=path/to/your/model.scad

Additional options are available for make engrave:

Lasercutting preview

To check if all lpart dimensions were defined correctly and nothing overlaps, run:

cd laserscad/dist
make preview model=path/to/your/model.scad

Note: Engravings are not shown in the preview.

Cleaning up

The _laserscad_temp folder can be deleted manually, or via:

cd laserscad/dist
make clean model=path/to/your/model.scad

Sheet Size

The default sheet size for arranging parts is 600x300 (millimeters). To export for a different size, add the parameters sheet_xlen=... sheet_ylen=... when calling make.

FAQ

What does laserscad do?

It simplifies and accelerates the process of creating 2D laser-cut objects with OpenSCAD.

What does laserscad not do?

It does not offer methods for creating boxes, different types of joints, and so on. There are, however, several other OpenSCAD libraries for this purpose (like lasercut or JointSCAD) which work great together with laserscad.

Meh, examples. Show me a real application.

That's not a question. Anyway, here you go: Korg Volca Case made with laserscad

How does it work internally?

Several steps are performed internally. The user's model is built with openscad. Meanwhile, laserscad echoes the ids and dimensions of every lpart, which are collected in a file. A python script reads this file and computes a position for every lpart. These positions are used when exporting 2D templates.