What a plugin is
A Stratal CAD plugin is a Windows x64 DLL with a manifest (stratal-plugin.json) in a folder named after the plugin's
id. Stratal CAD loads it at start-up when the package is signed by Stratal and the computer's licence includes it.
Its commands run through the same command dispatcher as Stratal CAD's own: they can be typed, put on the ribbon, run
from scripts, undone and redone, and they stop with Escape like any other command.
The SDK is plain C: one header, stratal/plugin_api.h, with a header-only C++17 wrapper, stratal/plugin.hpp. A
plugin links nothing from Stratal CAD, and no Qt type crosses the boundary.
A first command
#include "stratal/plugin.hpp"
namespace sdk = stratal::sdk;
class Mark final : public sdk::Command {
public:
sdk::Prompt begin(sdk::Context&) override {
sdk::Prompt p;
p.message = "Specify point";
p.point = true;
return p;
}
sdk::Prompt input(sdk::Context& ctx, const sdk::Input& in) override {
if (!in.isPoint()) return begin(ctx);
sdk::Edit edit = ctx.edit("MARK"); // one edit is one undo step
edit.addCircle(in.point, 1.0);
edit.commit(); // an edit not committed is rolled back
return finish();
}
};
void registerAll() { sdk::registerCommand<Mark>("MARK"); } // declared in the manifest too
STRATAL_DEFINE_PLUGIN("my-plugin", 1, 1, registerAll, nullptr)
Build it as a DLL (add_library(my_plugin MODULE ...) with the SDK's include folder) for Windows x64.
Rules of the interface
- One export,
stratal_plugin_entry(), returns the plugin's id and the API versions it accepts. They must equal the manifest's. initregisters the commands. It succeeds only if every command in the manifest was registered.- Every structure starts with
struct_size, and the host's function table only grows. Before calling a function added after the version you build against, check it withSTRATAL_API_HAS(api, name); the C++ wrapper throwsSTRATAL_E_UNSUPPORTEDon an older Stratal CAD, so your plugin can say it needs a newer one. - Strings the host returns are valid until the next call on the same handle. Only the drawing's thread may call the host.
- The drawing changes only inside an edit (
ctx.edit(...)...commit()): one edit per command run, one undo step. Objects on locked layers cannot be changed. - A command that fails ends with a message (
sdk::fail("...")in C++); its open edit is rolled back.
What a plugin can do
- Read the drawing: objects and their geometry, text, dimensions, hatches, blocks, layers, layouts, units, the selection and drawing properties.
- Change the drawing inside an edit: add, change and erase objects, layers, text and dimensions; solids where the 3D kernel is present.
- Keep its own data on objects (
plugin.<id>.<key>properties, saved in the drawing) and its own object types (custom entities, kept as read-only proxies when the plugin is not installed, so customers never lose work). - Show its tools: ribbon panels with buttons and split buttons, dock panels with rows and buttons, and a plain name
(
label) for every command on buttons, in menus and in Search tools. - Follow the drawing: events when drawings open, change or close, when commands end and when the selection changes.
- Long work in the background: a job runs on a worker thread and hands back a result, applied as one undo step.
- Write reports: PDF reports with tables, and workbooks, through Stratal CAD's own exports; files the user picks through Stratal CAD's file dialogs.
- Check the licence:
sdk::hasFeature("plugin.<id>")andsdk::licence()say what the person may do, so a plugin can explain why a command cannot run under the current licence and change nothing.
The header documents every function, its limits and its error codes.
The manifest
{
"schema": 1,
"id": "deck-builder",
"name": "Deck Builder",
"description": "Timber decks from an outline: joists, boards and a cutting list.",
"version": "1.0.0",
"publisher": { "id": "acme-tools", "name": "Acme Tools Ltd" },
"api": { "min": 1, "max": 1 },
"platform": "windows-x64",
"entry": "deck_builder.dll",
"entitlement": "plugin.deck-builder",
"capabilities": ["document.read", "document.write", "ui.ribbon"],
"contributes": {
"commands": [{ "name": "DECKBUILD", "label": "Build deck", "aliases": [], "description": "Build a deck from a closed outline", "category": "Building" }],
"ribbon_panels": [{ "tab": "Plugins", "panel": "Decks", "commands": ["DECKBUILD"] }]
}
}
id: lower-case letters and digits with single hyphens, at most 48 characters, the same as the package folder. Stratal's own plugin ids are reserved.publisher.id: your publisher id, as approved by Stratal. A package naming another publisher is refused.version: semantic versionMAJOR.MINOR.PATCH, with an optional pre-release (1.0.0-beta.1). Each submission is a new version.entitlement: exactlyplugin.<id>for a paid plugin, ornullfor a free one.capabilities: what the plugin needs:document.read,document.write,selection.read,ui.ribbon,ui.panel,file.read,file.write,network,process. They are shown to the customer and checked in review.- Commands: names in capitals (
^[A-Z][A-Z0-9_]{1,31}$) that do not clash with Stratal CAD's or another plugin's; alabelof 1 to 40 bytes for every command; adescriptionof at most 200 bytes. - The manifest's
descriptionis at most 1000 bytes; a dock panel lists at most 8 commands, and a plugin has at most 4 dock panels. "isolation": "process"makes the plugin always run in Stratal CAD's isolated worker (below).- Fields Stratal CAD does not know are refused, except display fields on commands and panels.
Isolation
Customers can run any plugin in the isolated worker: a separate, low-integrity process with a memory limit, no network
and no access to files outside its package. The interface is the same; every call becomes a round trip, and a crash
stops only the plugin (its open edit is rolled back). Plan for it: keep state in memory, read and write the user's files
through the file functions (saveFile, openFiles), and do not open windows of your own.
Translations
The manifest is always in English. To show your plugin in other languages, add one file per language to the package,
translations/<tag>.json beside the manifest (translations/de.json, translations/pt-BR.json), signed with the rest:
{
"schema": 1,
"language": "de",
"name": "Terrassenbau",
"description": "Holzterrassen aus einem Umriss: Balken, Dielen und eine Zuschnittliste.",
"commands": { "DECKBUILD": { "label": "Terrasse bauen", "description": "Eine Terrasse aus einem geschlossenen Umriss bauen" } },
"dock_panels": { "decks": { "title": "Terrassen" } },
"menus": { "Checks": "Prüfungen" }
}
languagematches the file's name. Everything else is optional: what a file leaves out stays English.- Commands, panel ids and menu titles (keyed by the menu's English title) must be your manifest's own. Limits as in the manifest: a label 1 to 40 bytes, a command description at most 200, a title 1 to 40, the name at most 80.
- Command names, aliases and categories never change: scripts and other plugins rely on them.
- Stratal CAD shows the language the user chose in Settings (or Windows' language) where your plugin has it, and English otherwise. A file that does not read is left out and the plugin is shown in English; it never stops the plugin.
- Older versions of Stratal CAD ignore the files. Use professional translators: machine translation reads badly in a paid product.
Packages, review and signing
- Put the DLL, the manifest and any data files in one folder named after the plugin's id. Every file in the folder is signed; a file added later stops the plugin loading.
- Zip the folder and upload it on the publisher page in the customer portal. It is checked at once: a valid manifest, a plugin id that is free or already yours, your publisher id, a paid or free entitlement, and a version not submitted before.
- Stratal reviews it. An approved version is signed with Stratal's plugin key and, when Stratal publishes it, listed and offered in Stratal CAD's Get plugins window. A rejected version comes back with a note.
- Customers install it from Get plugins (or Install from file). Stratal CAD checks the signature and every file before loading it, and refuses a package that was changed.
Stratal CAD loads only packages signed by Stratal, for every publisher: there is no developer mode for unsigned builds. Test the parts of your plugin that do not need Stratal CAD (geometry, calculations, file formats) in your own test programs, and submit a pre-release version (such as 1.0.0-beta.1) when you need it reviewed and signed.
Prices and sales
The price is agreed with Stratal when your plugin is approved; customers pay through Stratal's checkout, and your share of each sale is recorded at the rate agreed with you. Your sales, shares and payouts are on the publisher page. See publishing on Stratal and the developer agreement.
Good practice
- Give every command a plain
label("Build deck", not "DECKBUILD"), and give menus a title. - Keep everything a user typed in the drawing so it survives saving, and keep drawings working without your plugin.
- Say why something cannot be done, in plain words, and change nothing when a command is refused.
- Ship no sample data that could be mistaken for real figures (prices, rates, codes).