bambu-printer-mcp 1.1.71 → 1.1.72
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/README.md +2 -2
- package/dist/3mf_parser.d.ts +8 -0
- package/dist/3mf_parser.js +46 -48
- package/dist/ams-mapping.js +3 -1
- package/dist/counterpart/model-plates.d.ts +9 -0
- package/dist/counterpart/model-plates.js +10 -3
- package/dist/index.js +10 -18
- package/dist/safety/print-file.js +16 -7
- package/dist/safety/printer-state.js +3 -2
- package/dist/slicer/cli-exit-codes.d.ts +18 -0
- package/dist/slicer/cli-exit-codes.js +68 -0
- package/dist/slicer/layer-pauses.d.ts +7 -5
- package/dist/slicer/layer-pauses.js +8 -6
- package/dist/stl/stl-manipulator.js +35 -53
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
- package/src/3mf_parser.ts +46 -52
- package/src/ams-mapping.ts +3 -1
- package/src/counterpart/model-plates.ts +16 -3
- package/src/index.ts +10 -25
- package/src/safety/print-file.ts +17 -4
- package/src/safety/printer-state.ts +3 -2
- package/src/slicer/cli-exit-codes.ts +68 -0
- package/src/slicer/layer-pauses.ts +8 -6
- package/src/stl/stl-manipulator.ts +33 -54
- package/src/types.ts +6 -0
|
@@ -11,8 +11,10 @@ import { EventEmitter } from 'events';
|
|
|
11
11
|
import * as crypto from 'crypto';
|
|
12
12
|
import { execFile } from 'child_process';
|
|
13
13
|
import { keepSlice, restoreSlice, sliceCacheKey } from '../slicer/slice-cache.js';
|
|
14
|
+
import { listModelPlates } from '../counterpart/model-plates.js';
|
|
14
15
|
import { flattenForCli, detectProfilesRoot, resolveBblMachineProfile } from '../slicer/profile-flatten.js';
|
|
15
16
|
import { plainSlicerError, UNKNOWN_SLICER_ERROR } from '../slicer/slicer-messages.js';
|
|
17
|
+
import { bambuCliExitCode } from '../slicer/cli-exit-codes.js';
|
|
16
18
|
import { applyProcessOverrides, type ProcessOverrides } from '../slicer/process-overrides.js';
|
|
17
19
|
import { profileJsonFiles } from '../slicer/profile-files.js';
|
|
18
20
|
import { materializeOrcaProfilesRoot, stageOrcaCliProfiles } from '../slicer/orca-profile-cache.js';
|
|
@@ -26,11 +28,13 @@ const BAMBU_PROFILE_ROOTS = [
|
|
|
26
28
|
'/Applications/BambuStudio.app/Contents/Resources/profiles/BBL',
|
|
27
29
|
'/Applications/OrcaSlicer.app/Contents/Resources/profiles/BBL',
|
|
28
30
|
];
|
|
31
|
+
// curr_bed_type's enum keys (Bambu Studio 02.08.02.61 libslic3r/PrintConfig.cpp:437-445).
|
|
29
32
|
const BAMBU_CLI_BED_TYPES: Record<string, string> = {
|
|
30
33
|
textured_plate: 'Textured PEI Plate',
|
|
31
34
|
cool_plate: 'Cool Plate',
|
|
32
35
|
engineering_plate: 'Engineering Plate',
|
|
33
36
|
hot_plate: 'High Temp Plate',
|
|
37
|
+
supertack_plate: 'Supertack Plate',
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
// Define types for progress tracking
|
|
@@ -291,38 +295,14 @@ function describeSlicerFailure(
|
|
|
291
295
|
return `Slicer failed: the slicer ${status}${reason ? ` (${reason})` : ""}. ${error.message.trim()}${output ? `\nSlicer output: ${output}` : ""}`;
|
|
292
296
|
}
|
|
293
297
|
|
|
294
|
-
// Bambu Studio and OrcaSlicer CLI errors (libslic3r/Utils.hpp). The process
|
|
295
|
-
// exits with the low byte of the code; result.json names the error.
|
|
296
|
-
const BAMBU_CLI_ERRORS: Record<number, string> = {
|
|
297
|
-
[-2]: "invalid parameters to the slicer",
|
|
298
|
-
[-3]: "input files not found",
|
|
299
|
-
[-5]: "preset file cannot be parsed",
|
|
300
|
-
[-6]: "model file cannot be parsed",
|
|
301
|
-
[-9]: "copying objects failed",
|
|
302
|
-
[-17]: "printer is not compatible with the process preset",
|
|
303
|
-
[-21]: "auto-arranging objects failed",
|
|
304
|
-
[-22]: "auto-orienting objects failed",
|
|
305
|
-
[-50]: "a plate is empty or has no object fully inside it; arrange the model or place it on the plate",
|
|
306
|
-
[-51]: "incorrect slicing parameters",
|
|
307
|
-
[-52]: "objects extend over the bed boundary",
|
|
308
|
-
[-60]: "no printable objects remain after skipping",
|
|
309
|
-
[-61]: "filaments are not compatible with the plate type",
|
|
310
|
-
[-62]: "the filaments' temperatures differ too much",
|
|
311
|
-
[-63]: "objects collide in print-by-object mode",
|
|
312
|
-
[-64]: "objects collide",
|
|
313
|
-
[-100]: "slicing the model failed",
|
|
314
|
-
[-101]: "G-code conflicts after slicing",
|
|
315
|
-
[-102]: "G-code in an unprintable area",
|
|
316
|
-
};
|
|
317
|
-
|
|
318
298
|
function bambuCliFailureReason(exitCode: unknown, cli: CliResultSource): string | undefined {
|
|
319
299
|
const result = readCliResult(cli);
|
|
320
300
|
if (typeof result?.error_string === "string" && result.error_string.trim()) {
|
|
321
301
|
return `${result.error_string.trim()} [${result.return_code}]`;
|
|
322
302
|
}
|
|
323
303
|
if (typeof exitCode !== "number") return undefined;
|
|
324
|
-
const
|
|
325
|
-
return
|
|
304
|
+
const known = bambuCliExitCode(exitCode);
|
|
305
|
+
return known ? `${known.sentence} [${known.code}]` : undefined;
|
|
326
306
|
}
|
|
327
307
|
|
|
328
308
|
export class STLManipulator extends EventEmitter {
|
|
@@ -816,11 +796,6 @@ export class STLManipulator extends EventEmitter {
|
|
|
816
796
|
private resolveBambuStudioBedType(bedType?: string): string | undefined {
|
|
817
797
|
if (!bedType) return undefined;
|
|
818
798
|
const normalized = bedType.trim().toLowerCase();
|
|
819
|
-
if (normalized === 'supertack_plate') {
|
|
820
|
-
throw new Error(
|
|
821
|
-
'BambuStudio CLI SuperTack bed type is not verified; use a pre-sliced 3MF or choose textured_plate, cool_plate, engineering_plate, or hot_plate.'
|
|
822
|
-
);
|
|
823
|
-
}
|
|
824
799
|
return BAMBU_CLI_BED_TYPES[normalized] || bedType;
|
|
825
800
|
}
|
|
826
801
|
|
|
@@ -1786,34 +1761,38 @@ export class STLManipulator extends EventEmitter {
|
|
|
1786
1761
|
this.sliceSTLOnce(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, options);
|
|
1787
1762
|
const layers = bambuOptions?.pauseAtLayers?.length ? bambuOptions.pauseAtLayers : undefined;
|
|
1788
1763
|
const cli = slicerType === 'bambustudio' || slicerType === 'orcaslicer' || slicerType === 'orcaslicer-bambulab';
|
|
1789
|
-
|
|
1790
|
-
//
|
|
1791
|
-
|
|
1792
|
-
if (!layers
|
|
1793
|
-
if (
|
|
1764
|
+
// Without new pauses the CLI keeps the project's own pauses and colour changes itself: it loads a
|
|
1765
|
+
// Bambu 3MF's Metadata/custom_gcode_per_layer.xml with the project (Bambu Studio 02.08.02.61
|
|
1766
|
+
// BambuStudio.cpp:1882, bbs_3mf.cpp:2051), so nothing is passed.
|
|
1767
|
+
if (!layers) return once(bambuOptions);
|
|
1768
|
+
if (!cli) {
|
|
1794
1769
|
throw new Error(`Pausing at a layer needs the Bambu Studio or OrcaSlicer CLI, not ${slicerType}.`);
|
|
1795
1770
|
}
|
|
1771
|
+
const chosenPlate = bambuOptions?.slicePlate && bambuOptions.slicePlate > 0 ? bambuOptions.slicePlate : undefined;
|
|
1772
|
+
const plate = chosenPlate ?? 1;
|
|
1773
|
+
const threeMf = /\.3mf$/i.test(stlFilePath);
|
|
1774
|
+
// --load-custom-gcodes replaces the whole per-plate map and holds one plate (--slice N, or plate 1 for
|
|
1775
|
+
// --slice 0: BambuStudio.cpp:2224-2233, 4005-4008), so slicing every plate would drop plates 2..n's own.
|
|
1776
|
+
if (threeMf && chosenPlate === undefined && (await listModelPlates(stlFilePath)).plate_count > 1) {
|
|
1777
|
+
throw new Error('Pausing at a layer works on one plate at a time. Choose the plate with slice_plate.');
|
|
1778
|
+
}
|
|
1779
|
+
// The map replaces the project's own entries for this plate, so they are merged in.
|
|
1780
|
+
const project = threeMf ? await readProjectCustomGcodes(stlFilePath, plate) : undefined;
|
|
1796
1781
|
const customGcodesFile = path.join(this.tempDir, `custom-gcodes-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
|
|
1797
1782
|
try {
|
|
1798
|
-
|
|
1799
|
-
if (
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
tops = layerTops(gcode);
|
|
1806
|
-
}
|
|
1807
|
-
const info = layers ? customGcodesWithPauses(tops, layers, project) : project!;
|
|
1808
|
-
await fs.promises.writeFile(customGcodesFile, JSON.stringify(info));
|
|
1783
|
+
// A pause sits at its layer's exact top Z; learn the tops from a slice without pauses.
|
|
1784
|
+
if (progressCallback) progressCallback(10, `Finding layer heights for the pause before layer ${layers.join(", ")}`);
|
|
1785
|
+
const plain = await once({ ...bambuOptions, pauseAtLayers: undefined, customGcodesFile: undefined });
|
|
1786
|
+
const plainGcode = await readPlateGcode(plain.path, plate);
|
|
1787
|
+
if (!plainGcode) throw new Error('The slicer wrote no plate G-code, so the pause layers cannot be placed.');
|
|
1788
|
+
const tops = layerTops(plainGcode);
|
|
1789
|
+
await fs.promises.writeFile(customGcodesFile, JSON.stringify(customGcodesWithPauses(tops, layers, project)));
|
|
1809
1790
|
const result = await once({ ...bambuOptions, customGcodesFile });
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
throw new Error(`The slicer did not place the pause before layer ${(missing.length ? missing : layers).join(", ")}. Nothing was sent to the printer.`);
|
|
1816
|
-
}
|
|
1791
|
+
const gcode = await readPlateGcode(result.path, plate);
|
|
1792
|
+
const placed = gcode ? pausedLayers(gcode, machinePauseGcode(gcode)) : [];
|
|
1793
|
+
const missing = layers.filter(layer => !placed.includes(layer));
|
|
1794
|
+
if (!gcode || missing.length || layerTops(gcode).length !== tops.length) {
|
|
1795
|
+
throw new Error(`The slicer did not place the pause before layer ${(missing.length ? missing : layers).join(", ")}. Nothing was sent to the printer.`);
|
|
1817
1796
|
}
|
|
1818
1797
|
return result;
|
|
1819
1798
|
} finally {
|
package/src/types.ts
CHANGED
|
@@ -87,13 +87,19 @@ export interface ThreeMFAmsRequirements {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export interface ThreeMFPlateObject {
|
|
90
|
+
/** The instance's identify_id: the id the printer's skip_objects command takes. */
|
|
90
91
|
id: number;
|
|
91
92
|
name: string;
|
|
93
|
+
/** Already skipped in this file (slice_info's skipped="true"). */
|
|
94
|
+
skipped: boolean;
|
|
95
|
+
/** First-layer area and box from plate_N.json, only when the name is unique on the plate. */
|
|
92
96
|
area: number | null;
|
|
93
97
|
bbox: unknown;
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
export interface ThreeMFPlateObjects {
|
|
97
101
|
plateIndex: number;
|
|
102
|
+
/** The plate was sliced with object labels, which the printer needs to skip objects. */
|
|
103
|
+
labelObjectEnabled: boolean;
|
|
98
104
|
objects: ThreeMFPlateObject[];
|
|
99
105
|
}
|