Extensions
Extensions add to ParametriQ CAD in JavaScript: machine post-processors for the G-code and HPGL your machines expect, design rules that check a drawing before it is cut, templates that build a new parametric drawing from a few dimensions, reports that count and measure what is in a drawing, and save extensions that record a drawing somewhere else each time it is saved. Some come with the app; you can change them and write your own.
| Kind | Declared with | Used from |
|---|---|---|
| Post-processors | postProcessor({…}) |
File › Export › Export with Post-Processor… |
| Design rules | designRule({…}) |
File › Check Design, and before every machine export |
| Templates | template({…}) |
File › Extensions › New from Template… |
| Reports | drawingReport({…}) |
File › Reports… |
| Save extensions | onSave({…}) |
Every File › Save and Save As… |
| Camera registration | cameraRegistration({…}) |
File › Send Using Machine Profile a machine profile that names it |
| Commands (in a package) | command({…}) |
Their menu items and toolbar buttons, a shortcut, File › Extensions › Run Command… |
| Menus and toolbar (in a package) | uiExtension({…}) |
The menus and toolbar, as the app starts |
All of them use the same drawing API as JavaScript functions in a drawing: the drawing's variables and points, and functions to make points and elements.
Automation scripts use the same API to open, change, export and save drawings without the
app's window - for an order or database system, or a batch of files: run them with PiQ run script.js from the
command line, or File › Extensions › Run Script….
Where extensions live
An extension file is a .js file of JavaScript that declares one or more extensions. ParametriQ CAD reads every
.js file in two folders when it starts:
- Its own
Extensionsfolder, beside the program: the post-processors, rules, templates and reports that come with it. - Yours: File › Extensions › Open Extensions Folder opens it (and makes it, the first time). Put your own files here; they are kept when the app is updated.
After changing a file, use File › Extensions › Reload Extensions: it reads them all again and says how many of each it found. A file that can't be read is left out, and the message says which file, which line and why.
A folder with a manifest.json is an extension package: its script, its strings in each language and its icons
together, with the permissions it uses. Packages can add commands, menu items, toolbar buttons and dialogs
to the window, and hide the app's own for a stripped-down workspace; File › Extensions › Manage Extensions… turns
each on or off.
The same folders hold the app's other libraries, each in a folder of its own: Parametric drawings for
Run Parametric, Parts for the Parts panel, Materials for File › New
(see Materials), Appearances for the 3D pages' materials (see Appearances), and
Ask Claude.md for Ask Claude. The materials and the appearances have editors of their own:
File › Extensions › Materials… and File › Extensions › Appearances… show the app's, make your own copies of
them, and change yours, without editing their files by hand. File › Extensions › Make Thumbnails… makes the
pictures Run Parametric shows of your own Parametric drawings (see Run Parametric).
To change one that comes with the app, copy its file to your folder, rename it, and change the copy (give the extensions in it new names, or both versions will be listed).
A file of extensions
// my-shop.js
postProcessor({
name: "Router 2",
base: "gcode",
options: { header: "(Router 2)" },
edit(lines, program, options) {
return [options.header, ...lines];
}
});
designRule({
name: "Nothing outside the sheet",
check(drawing) {
for (const e of drawing.elements)
if (e.bounds.maxX > 1600 || e.bounds.maxY > 1200)
report(`${e.id} is off the 1600 × 1200 sheet`, [e]);
}
});
Each declaration is an object with a name (shown in the menus and messages), an optional description (shown when
choosing it) and what that kind needs. Code at the top of the file (constants, helper functions) runs once when the
file is read and can be shared by everything in it.
Options
Post-processors, reports and templates can ask for settings: post-processors and reports their options, templates their parameters. Each is shown as a row of the dialog, and what was chosen is remembered for next time. Give them as an object, one property for each:
options: {
feed: { label: "Feed", type: "number", value: 1500, min: 1, max: 20000, unit: "mm/min",
description: "Used when an element has no tool feed of its own." },
coolant: { label: "Coolant", type: "bool", value: false },
header: { label: "Header", type: "text", value: "(Machine 1)" },
machine: { label: "Machine", type: "choice", values: ["Small", "Large"], value: "Large" }
}
| Property | Meaning |
|---|---|
label |
What the row says (the property's name if left out). |
type |
"number", "bool", "text" or "choice" (if left out: from the value, or "choice" if there are values). |
value |
Where it starts. |
values |
A choice's choices. |
min, max |
A number's limits. |
unit |
Shown after a number. |
description |
Shown under the label. |
Briefly: feed: 1500 is a number, coolant: false a switch, header: "(M1)" text and
machine: ["Small", "Large"] a choice (the first chosen to start with).
What extensions can do
Extensions are sandboxed. They can read and make geometry through the drawing API, and
nothing else: no files, network, programs or settings of the computer. A call stops if it runs more than a million
statements or ten seconds, calls itself more than 200 deep, or uses too much memory. Unlike a JavaScript function in a
drawing, an extension may use Date and Math.random() (a post-processor can date its output).
Design rules, reports, post-processors and save extensions only look at the drawing: one that tries to change it is stopped with a message. A template's drawing is new, and it makes it as it wishes.
See also: Drawing API, JavaScript functions, G-code, HP-GL.