Examples
These scripts ship with Modlumi. On Windows they’re in
C:\Program Files\modlumi\scripting\examples, and on Linux in
share/modlumi/examples inside the installation, together with a
tsconfig.json that type-checks them as described in
Getting started.
Run them as they are, or paste them into the script console.
Draw an outline
Section titled “Draw an outline”Draws a one-meter square. Closing the outline creates a face.
// Draws a one-meter square; closing the outline creates a face.const model = modlumi.activeModel;model.operation("Draw outline", () => { model.entities.addEdges([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]]);});console.log(model.entities.length);Inspect a model
Section titled “Inspect a model”Lists the root entities, component definitions and materials of the open model. Run it against an existing file:
modlumi --background model.skp --run-script inspect.js// Lists the root entities, definitions, and materials of the open model.const model = modlumi.activeModel;for (const entity of model.entities) { console.log(entity.type, entity.entityId); switch (entity.type) { case "Edge": console.log(" length:", entity.length, "m"); break; case "Face": console.log(" area:", entity.area, "m²"); break; }}for (const definition of model.definitions) { console.log("Definition:", definition.name, definition.entities.length);}for (const material of model.materials) { console.log("Material:", material.name, material.color);}Export an image
Section titled “Export an image”Extrudes a box and saves a PNG from a fixed camera. See Image export for where this works.
// Extrudes a box and exports a PNG from a fixed camera (Linux builds with headless rendering).const { Camera } = modlumi;const model = modlumi.activeModel;model.operation("Box", () => { model.entities.addEdges([[0, 0, 0], [4, 0, 0], [4, 3, 0], [0, 3, 0], [0, 0, 0]]); const [face] = model.entities.ofType("Face"); face.extrude(2);});const view = model.activeView;view.camera = new Camera([5, -7, 5.5], [2, 1.5, 1], { perspective: false, fieldOfView: 35 });view.writeImage("box.png", { width: 640, height: 480 });More recipes
Section titled “More recipes”- Walk every group and component with world coordinates.
- Select faces by area.
- Build a box by extruding a rectangle.
- Make a radial array.
- Render a model from four sides.