Skip to content

Vibe coding a plugin? Teach your agent Modlumi first. Works with Claude Code, Codex, Cursor and more.

Examples

These scripts ship with Modlumi for Windows, in C:\Program Files\modlumi\scripting\examples, 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.

Draws a one-meter square. Closing the outline creates a face.

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(model.entities.length);

Builds a table from a box and four cylinders. Each solid is its own group.

table.js
// Builds a table from solids: a box for the top and four cylinders for the legs.
const model = modlumi.activeModel;
const width = 1.6;
const depth = 0.8;
const height = 0.72;
const inset = 0.1;
model.operation("Table", () => {
const entities = model.entities;
entities.addBox([0, 0, height], width, depth, 0.04).name = "Top";
for (const x of [inset, width - inset]) {
for (const y of [inset, depth - inset]) {
entities.addCylinder([x, y, 0], 0.03, height).name = "Leg";
}
}
});
console.log(model.entities.ofType("Group").length);

Lists the root entities, component definitions and materials of the open model. Run it against an existing file:

Terminal window
modlumi --background model.skp --run-script inspect.js
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);
}

Adds scenes that look at the whole model from the front, from its four corners and from above, as one undo step. Click them in the Scenes panel to look around.

scenes.js
// Adds scenes that look at the whole model from the front, the four corners and above, in one
// undo step, and lists every scene with where its camera stands.
const model = modlumi.activeModel;
const bounds = model.entities.bounds;
if (bounds === null) {
throw new Error("The model is empty");
}
const center = bounds.center;
const distance = bounds.diagonal * 1.5;
// Where each camera stands as seen from the center, scaled to the distance.
const views = [
{ name: "Front", direction: new modlumi.Vector3d(0, -1, 0.3) },
{ name: "Front left", direction: new modlumi.Vector3d(-1, -1, 0.6) },
{ name: "Front right", direction: new modlumi.Vector3d(1, -1, 0.6) },
{ name: "Back left", direction: new modlumi.Vector3d(-1, 1, 0.6) },
{ name: "Back right", direction: new modlumi.Vector3d(1, 1, 0.6) },
];
model.operation("Add views", () => {
for (const { name, direction } of views) {
const eye = center.offset(direction.normalize().scale(distance));
model.addScene(name, new modlumi.Camera(eye, center, { fieldOfView: 35 }));
}
// Looking straight down needs another up direction, and shows the plan without perspective.
const above = center.offset(new modlumi.Vector3d(0, 0, distance));
model.addScene("Plan", new modlumi.Camera(above, center, { up: [0, 1, 0], perspective: false }));
});
for (const scene of model.scenes) {
console.log(`${scene.name}: ${scene.camera.perspective ? "perspective" : "parallel"} from ${scene.camera.eye}`);
}

Extrudes a box and saves a PNG from a fixed camera. See Image export for where this works.

box.js
// Extrudes a box and exports a PNG from a fixed camera.
const { Camera } = modlumi;
const model = modlumi.activeModel;
model.operation("Box", () => {
model.entities.addRectangle([0, 0, 0], 4, 3).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 });