Post-processors
A post-processor writes a drawing for a machine in the form that machine wants: its own G-code dialect, a header and footer, a plotter's speed and force, codes for a laser's power. Use File › Export › Export with Post-Processor…: choose the post-processor, then where to save, then its options.
There are two kinds:
- From the cut list (
write): given every path to cut, as lines and arcs, it writes all the text itself. - From the built-in output (
baseandedit): the standard G-code or HP-GL is written first (with its options), and the post-processor changes its lines.
Before anything is written, the design rules are checked, as for any machine export.
Declaring one
postProcessor({
name: "Laser (G-code, no Z)",
description: "M3 / M5 round each cut.",
extension: "nc",
options: { feed: 1500, power: 1000 },
write(program, options) {
const out = ["G21", "G90"];
for (const job of program.jobs) {
if (job.drill || !job.cutting) continue;
out.push(`G0 X${job.segments[0].from.x} Y${job.segments[0].from.y}`, `M3 S${options.power}`);
for (const s of job.segments)
out.push(`G1 X${s.to.x} Y${s.to.y} F${options.feed}`);
out.push("M5");
}
out.push("M30");
return out;
}
});
| Property | Meaning |
|---|---|
name, description |
As shown when choosing it. |
extension |
The file extension written (nc if left out; plt with an HPGL base). |
base |
"gcode" or "hpgl": start from that export's output. Left out: write writes everything. |
options |
Its options, shown after the file is chosen. |
write(program, options) |
Without a base: returns the file's text, or an array of its lines. |
edit(lines, program, options) |
With a base: given the built-in output's lines; returns the text, or an array of lines. |
newLine |
What goes between the lines of an array returned ("\n" if left out; "\r\n" for machines that need it). |
options is an object of the values chosen, by name: options.feed, options.power.
The program
program describes what is to be cut, whichever kind the post-processor is:
| Property | Meaning |
|---|---|
name |
The drawing's file name, without its extension (PIQ if it hasn't been saved). |
units |
"mm" or "in". |
bounds |
{minX, minY, maxX, maxY} of everything cut (null if nothing is). |
jobs |
A job for each path, in the order the built-in exports cut them. |
Each job has:
| Property | Meaning |
|---|---|
element |
The element it comes from: "@12". |
layer, layerName |
Its layer's number and name. |
cutting |
Whether that layer is cut through (rather than creased, scored, drawn …). |
tool |
The element's tool settings, those it is cut with (its own, then its layer's from Production › Tool Options): number, name, diameter, spindleSpeed, clockwise, feedRate, plungeRate, startDepth, depth, stepDown, safeHeight, side, coolant, holeDiameter, peckDepth, dwell, pocket ("zigzag", "spiral" or "contour": the element is to be pocketed, not cut along), stepOver; or null. |
drill |
true for a hole to drill; then at (its centre) and diameter. |
closed |
Whether the path comes back to its start. |
segments |
The path, in order: {type: "line", from, to} or {type: "arc", from, to, centre, radius, clockwise}. Curves (Béziers, ellipses, splines) come as arcs and lines within 0.01 of them. |
Positions are {x, y} in the drawing's units.
Examples that come with the app
- Laser (G-code, no Z): writes G-code from the cut list, with the beam on (
M3 S…) and off (M5) round each cut, arcs asG2/G3withIandJ, creases cut only if asked. - G-code with header and footer: the built-in G-code, with lines of your own at its start and end (
|between them), the date, and comments left out if wanted. - HPGL cutting plotter: the built-in HPGL, with a speed (
VS) and force (FS) after each pen change.
Their file, machines.js, is in the app's Extensions folder: a good start for your own.
Notes
- What goes wrong is shown with the file and line:
machines.js, line 31: options.feed is not a number. print(…)andconsole.log(…)show values in the Interactive window, to see what the program holds.- The post-processor can read the drawing's variables (
variable("L")) and points (getPoint(4)), but not change the drawing.
To email a post-processor's output instead of saving it, use File › Send by Email › Export with Post-Processor…: see Emailing exports. See also: Extensions, G-code, HP-GL, Drawing API.