A library for efficient lasercutting with OpenSCAD.
- Laser whichever shape you want
- Model in 3D, then run one command to generate a 2D lasercutting template with all parts
- Save time, because 2D parts are arranged automatically
- Add engravings to identify parts (or to make things look fancy)
You will need:
- Debian/Ubuntu, Mac OS X or similar
openscad
2019.05, GNUmake
andpython3
installed
To set up the library:
- Configure OpenSCAD for command line usage
- Download a release and unpack it to a destination of your choice
- Move
laserscad.scad
from thedist
folder into your OpenSCAD library folder
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:
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:
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:
- The leg is created lying in the xy-plane and is later rotated using
lrotate
. This is necessary because laserscad needs lparts to lie in the xy-plane for lasercutting. Withlrotate
we rotate the part for our 3D preview of the final object. - As mentioned earlier, the string identifier passed to each
lpart
call needs to be globally unique. We added an extraid
parameter to the module and thelpart
call so that we can create multiple table leg parts with unique identifiers.
If we instantiate a leg with leg("left");
it will look like this:
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:
The full code for the example can be found at example/table.scad
.
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:
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
.
This section covers modules/operators offered by laserscad and parameters related to lasercutting.
include <laserscad.scad>
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]) { ... }
- id: identifier string, globally unique for each
lpart
call - [x, y]: x and y dimensions of the hull around the children
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
.
Similar to ltranslate
.
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.
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) { ... }
- parent_thick: Thickness (in z-direction) of the lpart this lengrave is applied to. Only affects the development preview.
- children_are_2d: Tells lengrave whether its children are a 2D object (
true
) or a 3D object (false
).
See docs/examples/engraving.scad
.
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) { ... }
- id: unique identifier string
- [x, y]: x and y dimensions of the hull around the children
- z: z dimension of the hull around the children
- thickness: slice thickness
See docs/examples/slicing.scad
.
Low Poly Stanford Bunny by johnny6 is licensed under the Creative Commons - Attribution - Non-Commercial license.
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=...);
- major: the exact major version required
- minor: minimum required minor version or
-1
to accept any minor version
major=0, minor=3
would accept laserscad 0.3.0, 0.3.1, 0.4.0, etc. but not 0.2.0 or 1.0.0major=1, minor=-1
would accept any laserscad 1.x.x (hence 1.0.0, 1.1.0, 1.1.1, etc.) but none of 0.x.x (0.3.0, 0.3.1, etc.)
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>
.
Compensate kerf (shrinkage caused by the laser beam) for all lparts in millimeters. Default = 0
Distance between lparts in the 2D template in millimeters. Default = 2
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
This is a reference of the commands for exporting a template for lasercutting or for engravings.
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.
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
:
model_unit
: By default, laserscad assumes that a length of 1 in OpenSCAD corresponds to 1mm in real life. A different unit can be specified, for examplemodel_unit=in
. The complete list of allowed values can be found in the W3C SVG specification.engrave_stroke_width
: By default, laserscad removes the outline in SVGs because it causes artifacts when engraving complex small shapes. The outline can be re-enabled by specifying a width, for exampleengrave_stroke_width=0.5
. Refer to the W3C SVG Strokes Specification for allowed values.
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.
The _laserscad_temp
folder can be deleted manually, or via:
cd laserscad/dist
make clean model=path/to/your/model.scad
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
.
It simplifies and accelerates the process of creating 2D laser-cut objects with OpenSCAD.
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.
That's not a question. Anyway, here you go: Korg Volca Case made with laserscad
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.