diff --git a/core/nodeslicer/nodes.py b/core/nodeslicer/nodes.py index 1b0e5c9..4592c56 100644 --- a/core/nodeslicer/nodes.py +++ b/core/nodeslicer/nodes.py @@ -832,6 +832,34 @@ class SLICENODE_GcodeToFile(ExecSliceNode): return 'ok' +@register_class +class SLICENODE_GcodeToTextBlock(ExecSliceNode): + bl_label = "Gcode to Text Block" + button_label = "Create Text Block" + + def init(self, context): + self._init_exec() + self.add_input("SLICESOCK_Gcode") + + def evaluate(self, operator=None): + gcode: str = resolve_input(self.inputs.get("Gcode")) + if not gcode: + return 'ok' + + text_block = bpy.data.texts.new(name="NodeSlicer_Gcode.gcode") + text_block.from_string(gcode) + + # Attempt to show in an open text editor + assert bpy.context.window_manager + for window in bpy.context.window_manager.windows: + for area in window.screen.areas: + if area.type == 'TEXT_EDITOR': + for space in area.spaces: + if space.type == 'TEXT_EDITOR': + space.text = text_block + + return 'ok' + @register_class class SLICENODE_StartPrint(ExecSliceNode): bl_label = "Start Print" diff --git a/core/nodeslicer/tree.py b/core/nodeslicer/tree.py index 9ecb079..2563188 100644 --- a/core/nodeslicer/tree.py +++ b/core/nodeslicer/tree.py @@ -76,6 +76,7 @@ class SLICENODE_MT_Menu(Menu): layout.operator("node.add_node", text="Boolean Paths").type = "SLICENODE_JoinSlices" layout.separator() layout.operator("node.add_node", text="Gcode to File").type = "SLICENODE_GcodeToFile" + layout.operator("node.add_node", text="Gcode to Text Block").type = "SLICENODE_GcodeToTextBlock" layout.operator("node.add_node", text="Start Print").type = "SLICENODE_StartPrint" layout.operator("node.add_node", text="Gcode to Mesh").type = "SLICENODE_GcodeToMesh" layout.operator("node.add_node", text="Executor").type = "SLICENODE_Executor" diff --git a/core/slice.py b/core/slice.py index ba382ce..bb0b5ca 100644 --- a/core/slice.py +++ b/core/slice.py @@ -515,6 +515,7 @@ class Pather(object): last_z = z0 gcode.append(f"G0 X{x0:.3f} Y{y0:.3f} Z{z0:.3f}") + old_x, old_y, old_z = x0, y0, z0 fr = self.feedrate old_fr = 0 diff --git a/doc/NODES.md b/doc/NODES.md index d4ec9b0..fa900cc 100644 --- a/doc/NODES.md +++ b/doc/NODES.md @@ -71,5 +71,6 @@ All nodes are found in the **Add (Shift+A)** menu under the **SliceNodes** categ - **Header**: Toggles the generation of standard NodeSlicer G-code headers and units setup. - **Load Gcode**: Reads a G-code file from disk. - **Gcode to File**: Writes G-code string to a file on disk. +- **Gcode to Text Block**: Creates a new Blender text block containing the G-code and opens it in any active text editors. - **Gcode to Mesh**: Decodes G-code and creates a Blender mesh ("Debug" object) for visualization. - **Test**: Triggers evaluation for debugging purposes.