For Developers
Writing a plug-in
A plug-in is a folder holding plugin.json and a JavaScript module. Tools ▸ Plug-ins ▸ New Plug-in… makes one to start from.
Documents\RazorCAD\Plugins\My Tools\
plugin.json
main.js
lib\sizes.js (more modules, imported by main.js: import { table } from './lib/sizes.js')
tables\sizes.json (data files, read with api.readJSON('tables/sizes.json'))
plugin.json describes it:
| Key | Meaning |
|---|---|
name | Its name, shown in Tools ▸ Plug-ins |
version, description, author | Shown in Tools ▸ Plug-ins |
tab | Its ribbon tab's name (the name when left out) |
main | Its module (main.js when left out) |
razorcad | The oldest RazorCAD it runs in, for example "0.21.5" |
The module exports activate(api), run when the plug-in starts, and may export deactivate(), run when it is turned off or reloaded. In activate it adds its commands:
export function activate(api) {
api.command({
id: 'plate', label: 'Plate with Holes', icon: 'extrude',
async run(rc) {
const v = await api.form('Plate with Holes', [
{ key: 'width', label: 'Width', type: 'number', unit: 'mm', value: 120, min: 1 },
{ key: 'thick', label: 'Thickness', type: 'number', unit: 'mm', value: 10, min: 0.1 },
]);
if (!v) return;
await rc.newPart(`Plate ${v.width}`);
const sk = await rc.sketch('top', (s) => s.centerRect(0, 0, v.width, 80));
await rc.extrude(sk, v.thick);
},
});
}
What api offers:
api.command({ id, label, icon, tooltip, in, run }) | A command on the plug-in's tab. in: 'part' (the default), 'assembly', 'drawing', or a list of them: the documents whose ribbon shows it. icon: the name of one of RazorCAD's icons, or SVG markup of its own. run(rc, api) runs as a macro does: rc is the macro API (see Macros and its API button), its changes to a part are one undo step and the part is rebuilt when it ends |
api.separator() | A separator between the tab's buttons |
api.form(title, fields, { ok, hint, remember }) | A form of values; resolves with { key: value }, or null if cancelled. Fields: { key, label, type, value, unit, min, max, options, hint }, with type 'number' (sums like 120/2 too), 'integer', 'text', 'select' (options: [[value, label], …] or values) or 'checkbox'. Numbers outside min and max are refused in the form. The values given last are offered again (unless remember: false) |
api.ask(question, value), api.choose(title, html, [[id, label, primary]…]), api.dialog(title, html or element, buttons) | A question, a choice, a dialog of its own |
api.status(text), api.toast(text, error) | A message in the status bar, a toast |
api.settings.get(key, default), .set(key, value), .all() | The plug-in's own settings, kept with RazorCAD's preferences |
api.readFile(path), api.readJSON(path) | A file of the plug-in's own folder: a table of sizes, a template |
api.on(event, fn) | 'rebuilt' (a part rebuilt: { doc, result }), 'opened' and 'saved' ({ path, kind }); returns a function that stops listening |
api.onStop(fn) | Something to undo when the plug-in stops |
api.run(id) | One of its commands, run as from its button |
api.app, api.M, api.S, api.razorcad.version | The whole application, the part model and sketch modules (as macros have them), RazorCAD's version |
The modules of a plug-in import each other with relative paths (./lib/x.js); modules importing each other in a circle aren't supported. A plug-in made of several files can be shared as a .zip of its folder, installed with Install….
Parts made by a plug-in are made of ordinary features, so they can be edited afterwards like any other part, and opened by anyone without the plug-in.
Rebuilding the executable
python -m pip install pywebview pyinstaller pillow
build.bat
build.bat bundles app/ (including the 23 MB OpenCascade WebAssembly kernel) and razorcad.py into RazorCAD.exe with PyInstaller. If RazorCAD is open, the running copy is renamed to RazorCAD.old.exe and the new build is used from the next launch.
installer\build_installer.bat builds RazorCAD.exe and then RazorCAD-Setup.exe. Set the version in version.txt first.
Code signing
Both builds sign RazorCAD.exe, the thumbnail DLL and the setup once a code-signing certificate is set up; until then they say "Not signed" and carry on. tools\sign.py --check shows how signing is set up. installer\SIGNING.md explains how to get a certificate and set it up (a certificate on a USB token or in Windows by its thumbprint, a .pfx file, or a cloud signing service).
Regression tests
python tests/run_tests.py
This rebuilds the test parts in tests/parts with the real geometry kernel in headless Microsoft Edge. It compares every body's volume, area, faces and edges (and flat patterns) with tests/expected.json, and the drawings of six test parts with their stored line counts and sizes. It also runs checks done as a user does them: sketching, dimensioning and extruding, drawings, assemblies, mates, references, standard parts, collisions, assembly features, macros, accessibility and more. It needs Python's playwright package and exits with 1 on any difference. --update stores new expected results, --only runs some of them, and --make-parts makes the test parts again from tests/make_parts.js. On a PC with 12 or more processor threads the run is split over several pages side by side (--jobs N; --jobs 1 runs everything in one page): about 27 s instead of 65 s on 24 threads. See tests/README.md.
- Timings: every run's times are kept per machine in
tests/perf-history.json(not in git). A test markedly slower than its usual time is listed under Performance;--perflists every time and--perf-strictfails the run on a slowdown. - On GitHub the tests run for every push and pull request (
.github/workflows/tests.yml), split over 6 machines side by side (--shard I/N, shared out by the times intests/test-weights.json): some 15 minutes.
Releases
Pushing a version tag (for example v0.14.0-beta, matching version.txt) runs .github/workflows/release.yml: the tests, then RazorCAD.exe and the setup are built and a draft release is made with the setup, its read-me, checksums and notes from CHANGELOG.md (tools/release_notes.py). A version that already has a release is left alone. See installer/RELEASING.md.
The geometry kernel builds
app/vendor/replicad holds two builds of the same Open CASCADE bindings: replicad_single (one thread) and replicad_multi (threads, with shared memory). Both are built from source: Open CASCADE 8.0.1 with two speed patches (the same results), opencascade.js 3.1.0 (Emscripten 6.0.5) with whole-program optimisation, replicad's bindings (commit a0bc495) with RazorCAD's additions, and tools/native/surface-patch.cpp (tools/native/README.md); tools/patch_surface_kernel_loader.py adjusts their loaders. The kernel worker loads the multi-threaded one when the app asks for more than one thread and the page is cross-origin isolated: the desktop app's server, serve.py and the tests' server send Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp for that. The website takes files up to 25 MiB, so tools/build_web_app.py publishes a bigger kernel in parts, which the worker joins.
The website and the browser version
python tools/build_website_docs.py builds the online manual (website/docs) from this manual's source and the browser version (tools/build_web_app.py). The browser version is built in its own folder, RazorCAD Web next to the project folder, with both kernels (website/_headers serves it cross-origin isolated, so it runs the multi-threaded one where the browser can), and copied from there into website/app; it carries the geometry kernel's signature so the browser keeps stored models per kernel.
python tools/check_site.py checks the website as it is served (razorcad.com, or another address): its pages, the browser version's isolation headers, and the browser version itself in headless Edge (it starts, and a multi-threaded kernel builds a part). GitHub runs it after each push that changes the website (.github/workflows/site-check.yml).
Working on the UI
Run python serve.py and open http://localhost:8765/ in a browser. In that mode files are downloaded instead of saved through dialogs. Set the RAZORCAD_DATA_DIR environment variable to keep a test run's recent-files list separate from your own.
Project layout
| Path | Purpose |
|---|---|
RazorCAD.exe | The application (built by build.bat) |
razorcad.py | Desktop shell: native window, file dialogs, auto-save (pywebview) |
app/js/main.js | Application controller: documents, commands, selection, files |
app/js/ui.js | Menus, Command ribbon, Feature tree, Property panel, dialogs |
app/js/model.js | Feature definitions, undo history, materials, sample part |
app/js/kernel.worker.js | Geometry kernel worker: replays the history with OpenCascade |
app/js/sketcher.js, sketchmodel.js, solver.js | Sketch mode, sketch data and the constraint solver |
app/js/sketch3d.js, sketch3dmodel.js | 3D sketches |
app/js/sheetmetal.js | Sheet metal features and flat patterns |
app/js/weldments.js, profiles.js | Fast Structure members and the profile tables |
app/js/assembly.js, asmview.js, explode.js | Assemblies, their display and exploded views |
app/js/drawing*.js, drawtemplates.js, pdf.js, dxf.js | Drawings, templates, sheet formats, PDF and DXF export |
app/js/claudespec.js | Modelling guide used by Ask Claude |
app/js/collide.js, asmfeatures.js, asmcuts.js, motion.js, stdparts.js | Collision detection, assembly holes and cuts, motion studies, standard parts |
app/js/macros.js, plugins.js, drawcheck.js, autodim.js, compare.js | Macros, plug-ins, Check Drawing, Auto Dimension, Compare With |
app/js/a11y.js, machine.js, kernelclient.js | Keyboard use and screen-reader labels; how many kernels the PC can run; the kernels |
kernelsig.py | The geometry kernel's signature (the model cache is kept per kernel) |
Manual/ | This manual: source, build script and change tracking |