Skip to content

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

Image export

model.activeView is an export View with its own camera. Set the camera, then call writeImage:

box_image.js
const { Camera } = modlumi;
const model = modlumi.activeModel;
model.operation("Box", () => {
model.entities.addFace([[0, 0, 0], [4, 0, 0], [4, 3, 0], [0, 3, 0]]).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 });

The image shows the committed model with its axes and background, but without the interface, tool previews or selection highlights. It’s rendered with four-sample antialiasing.

  • Call writeImage after the operation ends, so the edits are committed.
  • The file name must end in .png. A relative name is relative to the folder Modlumi was started from.
  • Width and height must be whole numbers between 1 and 8192 pixels.
  • Existing files are overwritten. The folder must already exist.
  • Invalid arguments throw TypeError or RangeError; rendering or file errors throw modlumi.ModelError.

A Camera is defined by an eye position and a target point in meters, and optionally an up direction, perspective and a vertical fieldOfView in degrees. Cameras are immutable, so assign a new camera to view.camera to change it. The export camera starts out as the standard camera and is separate from the camera in the window.

This renders the model from four sides:

const { Camera, Point3d } = modlumi;
const view = modlumi.activeModel.activeView;
["front", "right", "back", "left"].forEach((side, i) => {
const angle = -Math.PI / 2 + (i * Math.PI) / 2;
const eye = new Point3d(10 * Math.cos(angle), 10 * Math.sin(angle), 4);
view.camera = new Camera(eye, [0, 0, 1], { fieldOfView: 40 });
view.writeImage(`turntable-${side}.png`, { width: 400, height: 300 });
});

Image export doesn’t work in background runs yet: on Windows and Mac, scripts that save images need Modlumi’s window.