bambu-printer-mcp 1.1.74 → 1.1.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/counterpart/model-plates.d.ts +7 -1
- package/dist/counterpart/model-plates.js +8 -6
- package/dist/counterpart/plate-filaments.d.ts +8 -1
- package/dist/counterpart/plate-filaments.js +25 -8
- package/dist/fusion-mcp-bridge.d.ts +4 -0
- package/dist/fusion-mcp-bridge.js +24 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/counterpart/model-plates.ts +15 -7
- package/src/counterpart/plate-filaments.ts +24 -8
- package/src/fusion-mcp-bridge.ts +18 -0
- package/src/index.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PlateFilament } from "./plate-filaments.js";
|
|
1
|
+
import { type PaintLimits, type PlateFilament } from "./plate-filaments.js";
|
|
2
2
|
export interface ModelPlate {
|
|
3
3
|
/** Zero-based, as inspect_print_file's plate_index; slice_stl's slice_plate is index + 1. */
|
|
4
4
|
index: number;
|
|
@@ -21,6 +21,11 @@ export interface ModelPlate {
|
|
|
21
21
|
* Bambu Studio does for the objects on this plate (see plate-filaments.ts). Filaments of other plates never appear.
|
|
22
22
|
*/
|
|
23
23
|
filaments: PlateFilament[];
|
|
24
|
+
/**
|
|
25
|
+
* false when the plate's list may hold filaments it doesn't print: a part's mesh was too large to read its painting,
|
|
26
|
+
* so every declared filament is listed rather than risk leaving out one that prints. A client offers them all.
|
|
27
|
+
*/
|
|
28
|
+
filaments_complete: boolean;
|
|
24
29
|
/** The plate's own preview from the file (Metadata/plate_N.png), when asked for and present. */
|
|
25
30
|
thumbnail_png_base64?: string;
|
|
26
31
|
}
|
|
@@ -38,4 +43,5 @@ export interface ModelPlates {
|
|
|
38
43
|
}
|
|
39
44
|
export declare function listModelPlates(filePath: string, options?: {
|
|
40
45
|
thumbnails?: boolean;
|
|
46
|
+
paintLimits?: PaintLimits;
|
|
41
47
|
}): Promise<ModelPlates>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* is one plate. Only bounded metadata is read; nothing is extracted or run.
|
|
9
9
|
*/
|
|
10
10
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
11
|
-
import { plateFilaments } from "./plate-filaments.js";
|
|
11
|
+
import { PAINT_LIMITS, plateFilaments } from "./plate-filaments.js";
|
|
12
12
|
/** For the settings and plate files; the model file can be large and is only scanned. */
|
|
13
13
|
const MAX_METADATA_BYTES = 8 * 1024 * 1024;
|
|
14
14
|
const MAX_THUMBNAIL_BYTES = 2 * 1024 * 1024;
|
|
@@ -72,7 +72,7 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
72
72
|
const instanceId = Number(/<metadata\s+key="instance_id"\s+value="(\d+)"/.exec(instance[1])?.[1] ?? 0);
|
|
73
73
|
return objectId ? [{ objectId, instanceId }] : [];
|
|
74
74
|
}) });
|
|
75
|
-
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [],
|
|
75
|
+
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [], filaments_complete: true,
|
|
76
76
|
objects: [...match[1].matchAll(/<metadata\s+key="object_id"\s+value="(\d+)"/g)].flatMap(item => objects.get(item[1]) ? [objects.get(item[1])] : []) });
|
|
77
77
|
}
|
|
78
78
|
for (const name of Object.keys(zip.files)) {
|
|
@@ -82,7 +82,7 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
82
82
|
const number = Number(match[1]);
|
|
83
83
|
if (!valid(number))
|
|
84
84
|
continue;
|
|
85
|
-
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [] };
|
|
85
|
+
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true };
|
|
86
86
|
const layout = layouts.get(number) ?? { number, objectIds: [] };
|
|
87
87
|
layouts.set(number, layout);
|
|
88
88
|
if (match[2] === "gcode")
|
|
@@ -104,7 +104,7 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
104
104
|
result.plates = [...plates.values()].sort((a, b) => a.index - b.index);
|
|
105
105
|
// A standard single-build 3MF has no Bambu plate metadata: it is one plate.
|
|
106
106
|
if (!result.plates.length) {
|
|
107
|
-
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [] });
|
|
107
|
+
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true });
|
|
108
108
|
// Without plates every object is on the one plate.
|
|
109
109
|
layouts.set(1, { number: 1, objectIds: [...settings.matchAll(/<object\b[^>]*\bid="(\d+)"/g)].map(match => match[1]) });
|
|
110
110
|
}
|
|
@@ -119,9 +119,11 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
119
119
|
// A model file too large to read whole: its resources come first and its build items last (a plain 3MF).
|
|
120
120
|
const modelText = !modelBytes ? "" : modelBytes.length <= 64 * 1024 * 1024 ? modelBytes.toString("utf8")
|
|
121
121
|
: `${head}${modelBytes.subarray(-1024 * 1024).toString("utf8")}`;
|
|
122
|
-
const filaments = await plateFilaments(zip, settings, modelText, result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }));
|
|
123
|
-
for (const plate of result.plates)
|
|
122
|
+
const filaments = await plateFilaments(zip, settings, modelText, result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }), options.paintLimits ?? PAINT_LIMITS);
|
|
123
|
+
for (const plate of result.plates) {
|
|
124
124
|
plate.filaments = filaments.plates.get(plate.index + 1) ?? [];
|
|
125
|
+
plate.filaments_complete = !filaments.incomplete.has(plate.index + 1);
|
|
126
|
+
}
|
|
125
127
|
result.project_filaments = filaments.project;
|
|
126
128
|
if (options.thumbnails)
|
|
127
129
|
for (const plate of result.plates) {
|
|
@@ -56,6 +56,12 @@ export declare function readModelObjects(settings: string): ObjectEntry[];
|
|
|
56
56
|
* two bits, or, when both are set, 3 + the next nibble + 15 for every preceding 0b1111 nibble.
|
|
57
57
|
*/
|
|
58
58
|
export declare function paintedStates(paint: string): number[];
|
|
59
|
+
/** How much mesh text is read for painting: one file, and all of them together. */
|
|
60
|
+
export interface PaintLimits {
|
|
61
|
+
meshBytes: number;
|
|
62
|
+
totalBytes: number;
|
|
63
|
+
}
|
|
64
|
+
export declare const PAINT_LIMITS: PaintLimits;
|
|
59
65
|
export interface PlateLayout {
|
|
60
66
|
/** 1-based plate number. */
|
|
61
67
|
number: number;
|
|
@@ -73,8 +79,9 @@ export interface PlateLayout {
|
|
|
73
79
|
* The filaments each plate prints with, keyed by plate number. `settings` is model_settings.config, `model` the root
|
|
74
80
|
* 3D/3dmodel.model text.
|
|
75
81
|
*/
|
|
76
|
-
export declare function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[]): Promise<{
|
|
82
|
+
export declare function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[], limits?: PaintLimits): Promise<{
|
|
77
83
|
plates: Map<number, PlateFilament[]>;
|
|
84
|
+
incomplete: Set<number>;
|
|
78
85
|
project: PlateFilament[];
|
|
79
86
|
}>;
|
|
80
87
|
export {};
|
|
@@ -80,23 +80,30 @@ export function paintedStates(paint) {
|
|
|
80
80
|
}
|
|
81
81
|
return states;
|
|
82
82
|
}
|
|
83
|
+
export const PAINT_LIMITS = { meshBytes: MAX_MESH_BYTES, totalBytes: MAX_MESH_TOTAL };
|
|
83
84
|
/**
|
|
84
85
|
* Per component file and sub-object id, the painting of that mesh. Only files that contain painting are read in full.
|
|
86
|
+
* `unread` names the mesh files past the read limits: their painting is unknown, never taken as unpainted.
|
|
85
87
|
*/
|
|
86
|
-
async function readPainting(zip, paths) {
|
|
88
|
+
async function readPainting(zip, paths, limits) {
|
|
87
89
|
const result = new Map();
|
|
90
|
+
const unread = new Set();
|
|
88
91
|
let total = 0;
|
|
89
92
|
for (const path of paths) {
|
|
90
93
|
const file = zip.file(path);
|
|
91
94
|
if (!file)
|
|
92
95
|
continue;
|
|
93
|
-
// A mesh past the read budget is
|
|
96
|
+
// A mesh past the read budget is not read: its painting is unknown, and the listing says so.
|
|
94
97
|
const size = file._data?.uncompressedSize;
|
|
95
|
-
if (size !== undefined && (size >
|
|
98
|
+
if (size !== undefined && (size > limits.meshBytes || total + size > limits.totalBytes)) {
|
|
99
|
+
unread.add(path);
|
|
96
100
|
continue;
|
|
101
|
+
}
|
|
97
102
|
const bytes = await file.async("nodebuffer");
|
|
98
|
-
if (bytes.length >
|
|
103
|
+
if (bytes.length > limits.meshBytes || (total += bytes.length) > limits.totalBytes) {
|
|
104
|
+
unread.add(path);
|
|
99
105
|
continue;
|
|
106
|
+
}
|
|
100
107
|
if (!bytes.includes("paint_color=\""))
|
|
101
108
|
continue;
|
|
102
109
|
const text = bytes.toString("utf8");
|
|
@@ -118,7 +125,7 @@ async function readPainting(zip, paths) {
|
|
|
118
125
|
result.set(`${path}#${object[1]}`, paint);
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
|
-
return result;
|
|
128
|
+
return { painting: result, unread };
|
|
122
129
|
}
|
|
123
130
|
function projectFilaments(config) {
|
|
124
131
|
const list = (key) => Array.isArray(config[key]) ? config[key].map(String) : [];
|
|
@@ -135,7 +142,7 @@ function describe(index, project, name) {
|
|
|
135
142
|
* The filaments each plate prints with, keyed by plate number. `settings` is model_settings.config, `model` the root
|
|
136
143
|
* 3D/3dmodel.model text.
|
|
137
144
|
*/
|
|
138
|
-
export async function plateFilaments(zip, settings, model, plates) {
|
|
145
|
+
export async function plateFilaments(zip, settings, model, plates, limits = PAINT_LIMITS) {
|
|
139
146
|
const text = async (name) => {
|
|
140
147
|
const file = zip.file(name);
|
|
141
148
|
if (!file)
|
|
@@ -216,7 +223,9 @@ export async function plateFilaments(zip, settings, model, plates) {
|
|
|
216
223
|
for (const objectId of plate.objectIds)
|
|
217
224
|
for (const path of components.get(objectId)?.values() ?? [])
|
|
218
225
|
paintPaths.add(path);
|
|
219
|
-
const painting = await readPainting(zip, paintPaths);
|
|
226
|
+
const { painting, unread } = await readPainting(zip, paintPaths, limits);
|
|
227
|
+
// Plates with a part whose painting couldn't be read: they list every declared filament and say they're incomplete.
|
|
228
|
+
const incomplete = new Set();
|
|
220
229
|
const global = (key) => intOf(config[key]) ?? 0;
|
|
221
230
|
const FEATURES = ["wall_filament", "sparse_infill_filament", "solid_infill_filament"];
|
|
222
231
|
const result = new Map();
|
|
@@ -250,6 +259,14 @@ export async function plateFilaments(zip, settings, model, plates) {
|
|
|
250
259
|
const label = part.name || object.name;
|
|
251
260
|
const path = components.get(objectId)?.get(part.id);
|
|
252
261
|
const paint = path ? painting.get(`${path}#${part.id}`) : undefined;
|
|
262
|
+
// Its mesh is past the read limits: any declared filament may be painted on, so all of them are offered
|
|
263
|
+
// (a spare row, never a missing one), and the plate is marked incomplete.
|
|
264
|
+
// A sliced plate needs no painting: Studio's plate_N.json names its filaments, whatever another plate shares.
|
|
265
|
+
if (path && unread.has(path) && part.subtype === "normal_part" && !plate.slicedFilamentIds) {
|
|
266
|
+
incomplete.add(plate.number);
|
|
267
|
+
for (let index = 1; index <= declared; index++)
|
|
268
|
+
add(index, label);
|
|
269
|
+
}
|
|
253
270
|
for (const state of paint?.states ?? [])
|
|
254
271
|
if (part.subtype === "normal_part")
|
|
255
272
|
add(state, label);
|
|
@@ -321,5 +338,5 @@ export async function plateFilaments(zip, settings, model, plates) {
|
|
|
321
338
|
result.set(plate.number, [...used.entries()].sort((a, b) => a[0] - b[0]).map(([index, name]) => describe(index, project, name)));
|
|
322
339
|
}
|
|
323
340
|
// Every filament the project declares, used on a plate or not: slice_stl takes one profile per declared filament.
|
|
324
|
-
return { plates: result, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
341
|
+
return { plates: result, incomplete, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
325
342
|
}
|
|
@@ -177,6 +177,10 @@ function resultText(result) {
|
|
|
177
177
|
function failed(result, name) {
|
|
178
178
|
return result.isError === true || resultText(result).trimStart().startsWith(`**${name}** ERROR`);
|
|
179
179
|
}
|
|
180
|
+
/** The add-in's error kind from faust's "**tool** ERROR (KIND)" heading (fusion360_mcp/server.py), when it failed with one. */
|
|
181
|
+
function errorKind(result, name) {
|
|
182
|
+
return new RegExp(`^\\*\\*${name}\\*\\* ERROR \\(([A-Z_]+)\\)`).exec(resultText(result).trimStart())?.[1];
|
|
183
|
+
}
|
|
180
184
|
/** The value of one " key: value" line in faust's text result. */
|
|
181
185
|
function resultField(result, key) {
|
|
182
186
|
for (const line of resultText(result).split("\n")) {
|
|
@@ -228,6 +232,7 @@ export const FUSION_STATUS_OUTPUT_SCHEMA = {
|
|
|
228
232
|
connected: { type: "boolean", description: "The Fusion MCP server started and the add-in answered its ping." },
|
|
229
233
|
addinReachable: { type: "boolean", description: "The Fusion360MCP add-in answered a ping on FUSION_MCP_HOST:FUSION_MCP_PORT (default localhost:9877) within 2 s. Another program on that port, such as Blender's MCP add-on, does not count." },
|
|
230
234
|
fusionRunning: { type: "boolean" },
|
|
235
|
+
activeDesign: { type: "boolean", description: "When connected: whether Fusion has a design open, from the add-in's read-only get_design_type (false is its NO_ACTIVE_DESIGN). The pinned add-in refuses every design command, fusion_mcp_new_design included, without one (faust issue #12). Absent when unknown." },
|
|
231
236
|
tools: { type: "array", items: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } },
|
|
232
237
|
launched: { type: "boolean", description: "This call started Fusion." },
|
|
233
238
|
transport: { type: "string" },
|
|
@@ -449,6 +454,25 @@ export class FusionMcpBridge {
|
|
|
449
454
|
const ping = await this.invoke(live, options, dispatched, "ping", {});
|
|
450
455
|
result.connected = !failed(ping, "ping");
|
|
451
456
|
}
|
|
457
|
+
// Whether a design is open, from the add-in itself. get_design_type reads the active document's Design product
|
|
458
|
+
// (the add-in's _design(), as every design command does) and changes nothing; with no design it fails with the
|
|
459
|
+
// add-in's own error kind NO_ACTIVE_DESIGN (its hints.py). Any other answer leaves activeDesign out: unknown.
|
|
460
|
+
if (result.connected === true && live.tools.some(tool => tool.name === "get_design_type")) {
|
|
461
|
+
let read;
|
|
462
|
+
// A read that didn't finish (timeout, cancel, lost connection): Fusion isn't usable now. request() closes the
|
|
463
|
+
// cut-off session and names what happened, which status reports as its error.
|
|
464
|
+
try {
|
|
465
|
+
read = await this.invoke(live, options, dispatched, "get_design_type", {});
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
result.connected = false;
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
if (!failed(read, "get_design_type"))
|
|
472
|
+
result.activeDesign = true;
|
|
473
|
+
else if (errorKind(read, "get_design_type") === "NO_ACTIVE_DESIGN")
|
|
474
|
+
result.activeDesign = false;
|
|
475
|
+
}
|
|
452
476
|
});
|
|
453
477
|
}
|
|
454
478
|
catch (error) {
|
package/dist/index.js
CHANGED
|
@@ -2058,7 +2058,7 @@ class BambuPrinterMCPServer {
|
|
|
2058
2058
|
},
|
|
2059
2059
|
{
|
|
2060
2060
|
name: "list_3mf_plates",
|
|
2061
|
-
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2061
|
+
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. filaments_complete is false when a part's mesh was too large to read its painting: that plate then lists every declared filament, so offer them all rather than miss one that prints. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2062
2062
|
inputSchema: {
|
|
2063
2063
|
type: "object",
|
|
2064
2064
|
properties: {
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* is one plate. Only bounded metadata is read; nothing is extracted or run.
|
|
9
9
|
*/
|
|
10
10
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
11
|
-
import { plateFilaments, type PlateFilament, type PlateLayout } from "./plate-filaments.js";
|
|
11
|
+
import { PAINT_LIMITS, plateFilaments, type PaintLimits, type PlateFilament, type PlateLayout } from "./plate-filaments.js";
|
|
12
12
|
|
|
13
13
|
export interface ModelPlate {
|
|
14
14
|
/** Zero-based, as inspect_print_file's plate_index; slice_stl's slice_plate is index + 1. */
|
|
@@ -29,6 +29,11 @@ export interface ModelPlate {
|
|
|
29
29
|
* Bambu Studio does for the objects on this plate (see plate-filaments.ts). Filaments of other plates never appear.
|
|
30
30
|
*/
|
|
31
31
|
filaments: PlateFilament[];
|
|
32
|
+
/**
|
|
33
|
+
* false when the plate's list may hold filaments it doesn't print: a part's mesh was too large to read its painting,
|
|
34
|
+
* so every declared filament is listed rather than risk leaving out one that prints. A client offers them all.
|
|
35
|
+
*/
|
|
36
|
+
filaments_complete: boolean;
|
|
32
37
|
/** The plate's own preview from the file (Metadata/plate_N.png), when asked for and present. */
|
|
33
38
|
thumbnail_png_base64?: string;
|
|
34
39
|
}
|
|
@@ -55,7 +60,7 @@ const words = (value: string) => value
|
|
|
55
60
|
.replace(/&(?:amp|lt|gt|quot|apos);/g, entity => ({ "&": "&", "<": "<", ">": ">", """: "\"", "'": "'" }[entity]!))
|
|
56
61
|
.replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 256);
|
|
57
62
|
|
|
58
|
-
export async function listModelPlates(filePath: string, options: { thumbnails?: boolean } = {}): Promise<ModelPlates> {
|
|
63
|
+
export async function listModelPlates(filePath: string, options: { thumbnails?: boolean; paintLimits?: PaintLimits } = {}): Promise<ModelPlates> {
|
|
59
64
|
const { zip } = await readSafe3mfArchive(filePath);
|
|
60
65
|
const text = async (name: string) => {
|
|
61
66
|
const file = zip.file(name);
|
|
@@ -103,7 +108,7 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
103
108
|
const instanceId = Number(/<metadata\s+key="instance_id"\s+value="(\d+)"/.exec(instance[1])?.[1] ?? 0);
|
|
104
109
|
return objectId ? [{ objectId, instanceId }] : [];
|
|
105
110
|
}) });
|
|
106
|
-
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [],
|
|
111
|
+
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [], filaments_complete: true,
|
|
107
112
|
objects: [...match[1].matchAll(/<metadata\s+key="object_id"\s+value="(\d+)"/g)].flatMap(item => objects.get(item[1]) ? [objects.get(item[1])!] : []) });
|
|
108
113
|
}
|
|
109
114
|
for (const name of Object.keys(zip.files)) {
|
|
@@ -111,7 +116,7 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
111
116
|
if (!match) continue;
|
|
112
117
|
const number = Number(match[1]);
|
|
113
118
|
if (!valid(number)) continue;
|
|
114
|
-
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [] };
|
|
119
|
+
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true };
|
|
115
120
|
const layout = layouts.get(number) ?? { number, objectIds: [] };
|
|
116
121
|
layouts.set(number, layout);
|
|
117
122
|
if (match[2] === "gcode") plate.sliced = true;
|
|
@@ -129,7 +134,7 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
129
134
|
result.plates = [...plates.values()].sort((a, b) => a.index - b.index);
|
|
130
135
|
// A standard single-build 3MF has no Bambu plate metadata: it is one plate.
|
|
131
136
|
if (!result.plates.length) {
|
|
132
|
-
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [] });
|
|
137
|
+
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true });
|
|
133
138
|
// Without plates every object is on the one plate.
|
|
134
139
|
layouts.set(1, { number: 1, objectIds: [...settings.matchAll(/<object\b[^>]*\bid="(\d+)"/g)].map(match => match[1]) });
|
|
135
140
|
}
|
|
@@ -144,8 +149,11 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
144
149
|
const modelText = !modelBytes ? "" : modelBytes.length <= 64 * 1024 * 1024 ? modelBytes.toString("utf8")
|
|
145
150
|
: `${head}${modelBytes.subarray(-1024 * 1024).toString("utf8")}`;
|
|
146
151
|
const filaments = await plateFilaments(zip, settings, modelText,
|
|
147
|
-
result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }));
|
|
148
|
-
for (const plate of result.plates)
|
|
152
|
+
result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }), options.paintLimits ?? PAINT_LIMITS);
|
|
153
|
+
for (const plate of result.plates) {
|
|
154
|
+
plate.filaments = filaments.plates.get(plate.index + 1) ?? [];
|
|
155
|
+
plate.filaments_complete = !filaments.incomplete.has(plate.index + 1);
|
|
156
|
+
}
|
|
149
157
|
result.project_filaments = filaments.project;
|
|
150
158
|
if (options.thumbnails) for (const plate of result.plates) {
|
|
151
159
|
const file = zip.file(`Metadata/plate_${plate.index + 1}.png`);
|
|
@@ -114,20 +114,26 @@ export function paintedStates(paint: string): number[] {
|
|
|
114
114
|
/** What a mesh's painting says: the painted filament states, and whether any facet keeps the volume's own filament. */
|
|
115
115
|
interface MeshPaint { states: Set<number>; ownFilament: boolean }
|
|
116
116
|
|
|
117
|
+
/** How much mesh text is read for painting: one file, and all of them together. */
|
|
118
|
+
export interface PaintLimits { meshBytes: number; totalBytes: number }
|
|
119
|
+
export const PAINT_LIMITS: PaintLimits = { meshBytes: MAX_MESH_BYTES, totalBytes: MAX_MESH_TOTAL };
|
|
120
|
+
|
|
117
121
|
/**
|
|
118
122
|
* Per component file and sub-object id, the painting of that mesh. Only files that contain painting are read in full.
|
|
123
|
+
* `unread` names the mesh files past the read limits: their painting is unknown, never taken as unpainted.
|
|
119
124
|
*/
|
|
120
|
-
async function readPainting(zip: JSZip, paths: Set<string
|
|
125
|
+
async function readPainting(zip: JSZip, paths: Set<string>, limits: PaintLimits): Promise<{ painting: Map<string, MeshPaint>; unread: Set<string> }> {
|
|
121
126
|
const result = new Map<string, MeshPaint>();
|
|
127
|
+
const unread = new Set<string>();
|
|
122
128
|
let total = 0;
|
|
123
129
|
for (const path of paths) {
|
|
124
130
|
const file = zip.file(path);
|
|
125
131
|
if (!file) continue;
|
|
126
|
-
// A mesh past the read budget is
|
|
132
|
+
// A mesh past the read budget is not read: its painting is unknown, and the listing says so.
|
|
127
133
|
const size = (file as unknown as { _data?: { uncompressedSize?: number } })._data?.uncompressedSize;
|
|
128
|
-
if (size !== undefined && (size >
|
|
134
|
+
if (size !== undefined && (size > limits.meshBytes || total + size > limits.totalBytes)) { unread.add(path); continue; }
|
|
129
135
|
const bytes = await file.async("nodebuffer");
|
|
130
|
-
if (bytes.length >
|
|
136
|
+
if (bytes.length > limits.meshBytes || (total += bytes.length) > limits.totalBytes) { unread.add(path); continue; }
|
|
131
137
|
if (!bytes.includes("paint_color=\"")) continue;
|
|
132
138
|
const text = bytes.toString("utf8");
|
|
133
139
|
for (const object of text.matchAll(/<object\b[^>]*\bid="(\d+)"[^>]*>([\s\S]*?)<\/object>/g)) {
|
|
@@ -143,7 +149,7 @@ async function readPainting(zip: JSZip, paths: Set<string>): Promise<Map<string,
|
|
|
143
149
|
result.set(`${path}#${object[1]}`, paint);
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
|
-
return result;
|
|
152
|
+
return { painting: result, unread };
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
interface ProjectFilaments { colours: string[]; materials: string[]; ids: string[]; config: Record<string, unknown> }
|
|
@@ -176,7 +182,8 @@ export interface PlateLayout {
|
|
|
176
182
|
* The filaments each plate prints with, keyed by plate number. `settings` is model_settings.config, `model` the root
|
|
177
183
|
* 3D/3dmodel.model text.
|
|
178
184
|
*/
|
|
179
|
-
export async function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[]
|
|
185
|
+
export async function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[], limits: PaintLimits = PAINT_LIMITS)
|
|
186
|
+
: Promise<{ plates: Map<number, PlateFilament[]>; incomplete: Set<number>; project: PlateFilament[] }> {
|
|
180
187
|
const text = async (name: string) => {
|
|
181
188
|
const file = zip.file(name);
|
|
182
189
|
if (!file) return "";
|
|
@@ -248,7 +255,9 @@ export async function plateFilaments(zip: JSZip, settings: string, model: string
|
|
|
248
255
|
const paintPaths = new Set<string>();
|
|
249
256
|
for (const plate of plates) if (!plate.slicedFilamentIds) for (const objectId of plate.objectIds)
|
|
250
257
|
for (const path of components.get(objectId)?.values() ?? []) paintPaths.add(path);
|
|
251
|
-
const painting = await readPainting(zip, paintPaths);
|
|
258
|
+
const { painting, unread } = await readPainting(zip, paintPaths, limits);
|
|
259
|
+
// Plates with a part whose painting couldn't be read: they list every declared filament and say they're incomplete.
|
|
260
|
+
const incomplete = new Set<number>();
|
|
252
261
|
|
|
253
262
|
const global = (key: string) => intOf(config[key]) ?? 0;
|
|
254
263
|
const FEATURES = ["wall_filament", "sparse_infill_filament", "solid_infill_filament"] as const;
|
|
@@ -279,6 +288,13 @@ export async function plateFilaments(zip: JSZip, settings: string, model: string
|
|
|
279
288
|
const label = part.name || object.name;
|
|
280
289
|
const path = components.get(objectId)?.get(part.id);
|
|
281
290
|
const paint = path ? painting.get(`${path}#${part.id}`) : undefined;
|
|
291
|
+
// Its mesh is past the read limits: any declared filament may be painted on, so all of them are offered
|
|
292
|
+
// (a spare row, never a missing one), and the plate is marked incomplete.
|
|
293
|
+
// A sliced plate needs no painting: Studio's plate_N.json names its filaments, whatever another plate shares.
|
|
294
|
+
if (path && unread.has(path) && part.subtype === "normal_part" && !plate.slicedFilamentIds) {
|
|
295
|
+
incomplete.add(plate.number);
|
|
296
|
+
for (let index = 1; index <= declared; index++) add(index, label);
|
|
297
|
+
}
|
|
282
298
|
for (const state of paint?.states ?? []) if (part.subtype === "normal_part") add(state, label);
|
|
283
299
|
// A modifier's own filament counts whatever its paint (Model.cpp:3384-3390).
|
|
284
300
|
if (part.subtype !== "normal_part" || !paint || paint.ownFilament) {
|
|
@@ -334,5 +350,5 @@ export async function plateFilaments(zip: JSZip, settings: string, model: string
|
|
|
334
350
|
result.set(plate.number, [...used.entries()].sort((a, b) => a[0] - b[0]).map(([index, name]) => describe(index, project, name)));
|
|
335
351
|
}
|
|
336
352
|
// Every filament the project declares, used on a plate or not: slice_stl takes one profile per declared filament.
|
|
337
|
-
return { plates: result, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
353
|
+
return { plates: result, incomplete, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
338
354
|
}
|
package/src/fusion-mcp-bridge.ts
CHANGED
|
@@ -189,6 +189,11 @@ function failed(result: CallToolResult, name: string): boolean {
|
|
|
189
189
|
return result.isError === true || resultText(result).trimStart().startsWith(`**${name}** ERROR`);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
/** The add-in's error kind from faust's "**tool** ERROR (KIND)" heading (fusion360_mcp/server.py), when it failed with one. */
|
|
193
|
+
function errorKind(result: CallToolResult, name: string): string | undefined {
|
|
194
|
+
return new RegExp(`^\\*\\*${name}\\*\\* ERROR \\(([A-Z_]+)\\)`).exec(resultText(result).trimStart())?.[1];
|
|
195
|
+
}
|
|
196
|
+
|
|
192
197
|
/** The value of one " key: value" line in faust's text result. */
|
|
193
198
|
function resultField(result: CallToolResult, key: string): string | undefined {
|
|
194
199
|
for (const line of resultText(result).split("\n")) {
|
|
@@ -242,6 +247,7 @@ export const FUSION_STATUS_OUTPUT_SCHEMA = {
|
|
|
242
247
|
connected: { type: "boolean", description: "The Fusion MCP server started and the add-in answered its ping." },
|
|
243
248
|
addinReachable: { type: "boolean", description: "The Fusion360MCP add-in answered a ping on FUSION_MCP_HOST:FUSION_MCP_PORT (default localhost:9877) within 2 s. Another program on that port, such as Blender's MCP add-on, does not count." },
|
|
244
249
|
fusionRunning: { type: "boolean" },
|
|
250
|
+
activeDesign: { type: "boolean", description: "When connected: whether Fusion has a design open, from the add-in's read-only get_design_type (false is its NO_ACTIVE_DESIGN). The pinned add-in refuses every design command, fusion_mcp_new_design included, without one (faust issue #12). Absent when unknown." },
|
|
245
251
|
tools: { type: "array", items: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } },
|
|
246
252
|
launched: { type: "boolean", description: "This call started Fusion." },
|
|
247
253
|
transport: { type: "string" },
|
|
@@ -449,6 +455,18 @@ export class FusionMcpBridge {
|
|
|
449
455
|
const ping = await this.invoke(live, options, dispatched, "ping", {});
|
|
450
456
|
result.connected = !failed(ping, "ping");
|
|
451
457
|
}
|
|
458
|
+
// Whether a design is open, from the add-in itself. get_design_type reads the active document's Design product
|
|
459
|
+
// (the add-in's _design(), as every design command does) and changes nothing; with no design it fails with the
|
|
460
|
+
// add-in's own error kind NO_ACTIVE_DESIGN (its hints.py). Any other answer leaves activeDesign out: unknown.
|
|
461
|
+
if (result.connected === true && live.tools.some(tool => tool.name === "get_design_type")) {
|
|
462
|
+
let read: CallToolResult;
|
|
463
|
+
// A read that didn't finish (timeout, cancel, lost connection): Fusion isn't usable now. request() closes the
|
|
464
|
+
// cut-off session and names what happened, which status reports as its error.
|
|
465
|
+
try { read = await this.invoke(live, options, dispatched, "get_design_type", {}); }
|
|
466
|
+
catch (error) { result.connected = false; throw error; }
|
|
467
|
+
if (!failed(read, "get_design_type")) result.activeDesign = true;
|
|
468
|
+
else if (errorKind(read, "get_design_type") === "NO_ACTIVE_DESIGN") result.activeDesign = false;
|
|
469
|
+
}
|
|
452
470
|
});
|
|
453
471
|
} catch (error) {
|
|
454
472
|
result.error = error instanceof Error ? error.message : String(error);
|
package/src/index.ts
CHANGED
|
@@ -2569,7 +2569,7 @@ class BambuPrinterMCPServer {
|
|
|
2569
2569
|
},
|
|
2570
2570
|
{
|
|
2571
2571
|
name: "list_3mf_plates",
|
|
2572
|
-
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2572
|
+
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. filaments_complete is false when a part's mesh was too large to read its painting: that plate then lists every declared filament, so offer them all rather than miss one that prints. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2573
2573
|
inputSchema: {
|
|
2574
2574
|
type: "object",
|
|
2575
2575
|
properties: {
|