Export from a plugin
A plugin's export turns the part into flat drawings at 1:1: a leather pattern, the footprint of a box, a template to cut. The export gives Moket a layout of items made of lines, circles and text; Moket arranges the items, tiles them on pages and writes the files. The plugin never writes a file itself.
Access: the plugin's workbench, a button at the right of its toolbar, such as Export footprint.
Declare the export
In the manifest, each export has an id, the label of its button and the formats it offers:
json
"exports": [{ "id": "footprint", "label": "Export footprint", "formats": ["pdf", "svg", "dxf"] }]| Format | What Moket writes |
|---|---|
pdf-tiled | A PDF of A4 or A3 pages that overlap by 10 mm, with alignment marks and a page grid, to print at home |
pdf | A PDF of one sheet of a chosen size |
svg | An SVG in millimetres, a group per layer |
dxf | A DXF in millimetres, the same layers |
Every page and sheet has a 50 mm test square, so people can check that it printed at 100 %.
Write the export
In the module, exports has a function for each export id. It gets the plugin's features of the part, in history order, with the data each one returned when it was built:
ts
exports: {
async footprint(ctx) {
const boxes = ctx.features.filter((f) => f.type === 'com.example.rounded-box.box');
return {
items: boxes.map((f) => ({
id: f.id,
label: f.name,
detail: '60 x 40 mm',
shapes: [
{ kind: 'path', layer: 'cut', closed: true, points: [[-30, -20], [30, -20], [30, 20], [-30, 20]] },
{ kind: 'text', layer: 'text', at: [0, 0], text: f.name, height: 5, anchor: 'middle' },
],
})),
};
},
},Keep in a feature's data what its export needs, such as an outline in the feature's own coordinates: the export cannot read bodies or the kernel. A part rolled back in its history still exports everything: Moket builds it to the end for the export.
The layout
Each item is one thing to cut or print, in its own coordinates: millimetres, x to the right, y up. Moket places the items in rows and never turns them.
| Item field | What it is |
|---|---|
id | Stable across exports, such as the feature's id |
label | Its name in the export dialog, where people choose what to export |
detail | Optional, a line under it: cut 2 · veg-tan 1.4 mm |
shapes | What it is made of |
| Shape | Fields |
|---|---|
path | points, closed, dashed: lines through the points |
circle | center, radius, dashed |
text | at, text, height (of a capital letter, mm), angle (radians), anchor (start, middle, end) |
Every shape is on a layer: cut, stitch, fold, marks and text are Moket's, and a plugin may name others. In SVG and DXF each layer is a layer of its own, which laser and CNC software can cut, score or skip. A layout has at most 500 items, 200,000 points and 200 texts.