Skip to content

Write a plugin ​

A plugin adds features to the part editor, written in TypeScript the way Moket's own features are. Its features rebuild with the part, take expressions and parameters, and keep their faces' names, so later features, drawings and assemblies can build on them. This tutorial installs Rounded box, a small example plugin, then turns its source into a plugin of your own.

Access: this page. Plugins install in Settings > Plugins, see Install plugins.

Rounded box in the Boxes workbench, with its dialog made from its params

Download the starter ​

Moket Plugin SDK 1version 2026.10.20-a29c23b
Starter packageZIP · 20 KB
Rounded box with the SDK and a build: unzip it and make it yours.
Download
SDK typesD.TS · 35 KB
Everything '@moket/plugin-sdk' declares, in one file, for an editor or a build of your own.
Download

The starter package is Rounded box's source with the SDK and a build. You need Node.js 20 or later.

Try the example ​

  1. Open Settings > Plugins and click Install plugin.
  2. Paste https://app.moket.io/help/plugins/rounded-box/moket-plugin.json and press Enter.
  3. Click Install.
  4. Open a part, click the workbench at the right of the top bar and choose Boxes.
  5. Click Rounded box, turn on Hollow and click OK. The dialog says how much the box holds.
  6. Click Export footprint to export the box's outline at 1:1.

Rounded box makes a box on the XY plane around the origin. Its corners are round or cut off, and a hollow box is open at the top.

What a plugin is ​

A plugin is two files:

FileWhat it holds
moket-plugin.jsonThe manifest: the plugin's id, name and version, its features and their params, its workbench and its exports
plugin.jsOne ES module whose default export has a build for each feature and a function for each export, bundled with what it uses

Moket reads the manifest without running your code: it makes each feature's dialog from its params, checks the values people type, and keeps parts that use the plugin openable for people who do not have it. Your code runs only to build: Moket gives it the evaluated values and what it picked, and it gives back bodies. See Declare features and params.

Build it yourself ​

  1. Download the starter package and unzip it.

  2. In the rounded-box folder, install and build it:

    sh
    npm install
    npm run build

    npm run build checks the types, then writes dist/plugin.js and dist/moket-plugin.json.

  3. Serve it to Moket from your computer:

    sh
    npm run serve
  4. In Moket, open Settings > Plugins > Install plugin and paste http://localhost:5199/moket-plugin.json. If you installed the example from the help site, the dialog says this one replaces it.

  5. Change something in src/plugin.ts, for example the message of fail, and run npm run build again.

  6. In Settings > Plugins, click Update next to Rounded box. Parts that use it rebuild with the new code when you open them.

Moket installs plugins from https addresses, and from http://localhost only while you write one.

Read the code ​

src/plugin.ts exports the plugin with definePlugin, which checks its shape in your editor:

ts
import { definePlugin, fail, nameResult, sweepSeeds } from '@moket/plugin-sdk';

export default definePlugin({
  features: {
    'com.example.rounded-box.box': {
      async build(ctx, params) {
        const width = ctx.value('width'); // mm, from the expression typed
        const hollow = params['hollow'] === true;
        // ...
        if (2 * radius >= Math.min(width, depth))
          throw fail(
            'The corners take the whole side: make them smaller',
            'radius',
          );
        const face = await ctx.kernel.makeProfileFace(plane, [segments]);
        const solid = await ctx.kernel.extrude(
          face.shape,
          plane.normal,
          height,
        );
        // ...
        return { bodies: { [params['body'] as string]: body }, data };
      },
    },
  },
  exports: {
    async footprint(ctx) {
      // ...
    },
  },
});
  • ctx.value(name) gives a number param's value, in millimetres, radians or as a plain number. Choices, switches and picks are in params.
  • ctx.kernel makes and changes shapes: profiles, extrusions, booleans, fillets, shells and more.
  • fail(message, param) stops the feature with a message on the field to change. ctx.report adds a note or a warning, like Holds 46.1 ml.
  • The result names every face, so features built on the box keep their references when its sizes change. nameResult and sweepSeeds do it the way Moket's Extrude does.
  • data keeps what the export needs, the box's sizes.

See Build a feature and Export from a plugin.

Make it yours ​

  1. In moket-plugin.json, change id to a reverse domain of your own, such as com.yourname.tools. Every feature type starts with it.
  2. Change name, the features and their params, and the workbench's tools.
  3. Write each feature's build in src/plugin.ts, under its type.
  4. Raise version when you change the plugin, and a feature's version when you change its params.
  5. Build, then click Update in Moket.

Share it ​

  • By address: put the two files of dist/ on an https site that lets other sites fetch them (CORS), such as GitHub Pages, and share the address of moket-plugin.json.
  • By file: zip the dist folder and share the zip. People install it with or choose a package file (.zip).

People who install your plugin get the version they installed. When you publish a new one, they get it when they click Update.

Use the SDK without the starter ​

The SDK's types download as one file, moket-plugin-sdk.d.ts. Save it in your project and map @moket/plugin-sdk to it in tsconfig.json:

json
{
  "compilerOptions": {
    "paths": { "@moket/plugin-sdk": ["./moket-plugin-sdk.d.ts"] }
  }
}

Its helpers (definePlugin, fail, nameResult, nameEdges, faceName, sweepSeeds) are in the starter's sdk/index.js; bundle them into your module. The bundle must be one ES module of at most 2 MB, with no imports left.

Moket Help