diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index f776c6f0c1..d3db35e762 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -10,18 +10,17 @@ import io class GCodeWriter(MeshWriter): def __init__(self): super().__init__() - self._gcode = None - def write(self, file_name, storage_device, mesh_data): - if "gcode" in file_name: - scene = Application.getInstance().getController().getScene() - gcode_list = getattr(scene, "gcode_list") - if gcode_list: - f = storage_device.openFile(file_name, "wt") - Logger.log("d", "Writing GCode to file %s", file_name) - for gcode in gcode_list: - f.write(gcode) - storage_device.closeFile(f) - return True + def write(self, stream, node, mode = MeshWriter.OutputMode.TextMode): + if mode != MeshWriter.OutputMode.TextMode: + Logger.log("e", "GCode Writer does not support non-text mode") + return False + + scene = Application.getInstance().getController().getScene() + gcode_list = getattr(scene, "gcode_list") + if gcode_list: + for gcode in gcode_list: + stream.write(gcode) + return True return False diff --git a/plugins/GCodeWriter/__init__.py b/plugins/GCodeWriter/__init__.py index 65f53f64c3..4f0b5dd82a 100644 --- a/plugins/GCodeWriter/__init__.py +++ b/plugins/GCodeWriter/__init__.py @@ -13,15 +13,17 @@ def getMetaData(): "name": "GCode Writer", "author": "Ultimaker", "version": "1.0", - "description": catalog.i18nc("GCode Writer Plugin Description", "Writes GCode to a file") + "description": catalog.i18nc("GCode Writer Plugin Description", "Writes GCode to a file"), + "api": 2 }, "mesh_writer": { - "extension": "gcode", - "description": catalog.i18nc("GCode Writer File Description", "GCode File"), - "mime_types": [ - "text/x-gcode" - ] + "output": [{ + "extension": "gcode", + "description": catalog.i18nc("GCode Writer File Description", "GCode File"), + "mime_type": "text/x-gcode", + "mode": GCodeWriter.GCodeWriter.OutputMode.TextMode + }] } }