Getting started
Modlumi scripts are JavaScript. Modlumi runs them in its own built-in
JavaScript engine, so you don’t need to install anything to run a script.
Everything a script needs is on the global modlumi namespace: get the open
model from modlumi.activeModel, then read or edit it.
Write a script
Section titled “Write a script”Create a file called outline.js:
// Draws a one-meter square with edges, then fills it; edges alone make no face.const model = modlumi.activeModel;model.operation("Draw outline", () => { const [side] = model.entities.addEdges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]]); model.entities.findFaces(side);});console.log(`The model has ${model.entities.length} elements`);A few things to notice:
modlumi.activeModelis the model the script runs against.- Every edit happens inside
model.operation(name, () => { ... }). The operation becomes one step in Edit → Undo. See Operations and undo. - Coordinates are in meters. Use
modlumi.mm()ormodlumi.inches()to convert other units.
Run it
Section titled “Run it”In Modlumi, choose File → Run Script… and pick outline.js. The square
appears in the model, and the console.log output appears in
Scripting → Script Console.
To try something without a file, paste any example from these guides into the script console, or write it in Scripting → Script Editor. You can also run scripts from the command line, with or without a window. See Running scripts.
Completion and type checking
Section titled “Completion and type checking”Modlumi publishes type declarations for its API, so your editor can complete names, show documentation and catch mistakes before you run anything. Put two files next to your scripts:
modlumi.d.ts, the type declarations of the API;tsconfig.json, a starting configuration for the TypeScript compiler.
Both also ship with Modlumi for Windows, in
C:\Program Files\modlumi\scripting\types. Use the declarations that
match your Modlumi version, so new API members show up in your editor. The
API reference on this site is generated from the same file.
Editors such as Visual Studio Code pick up tsconfig.json and modlumi.d.ts
automatically, also for plain JavaScript files.
You can also write scripts in TypeScript. Modlumi runs JavaScript, so install TypeScript and compile the folder first:
npx tscThe compiler checks every script against modlumi.d.ts and writes the
JavaScript to dist/, so outline.ts becomes dist/outline.js. Run
npx tsc --watch while you work, so the .js files stay up to date every
time you save.
Next steps
Section titled “Next steps”- Model and entities shows how to find edges, faces, groups and components.
- Examples has complete scripts to adapt.
- Writing a plugin turns a script into a plugin that stays loaded; the source of every plugin that comes with Modlumi is in the modlumi-plugins repository.