Nodes/MKRShift_Nodes/G-code Preview
ComfyUI Node

G-code Preview

See the toolpath before you print — plans, meshes, or raw G-code, all in one preview

By criskb·Created 7 months ago·Updated 5 months ago· 0
G-code Preview
  • plan
  • mesh
  • profile
  • preview
  • preview_info_json
  • summary
  • plan
settings_json{"view_mode":"auto","preview_size":768}
gcode_text
gcode_path

You wouldn't commit an image to film without previewing it, and you shouldn't commit a toolpath to plastic without previewing it either. MKRGCodePreview is the pack's eyeball stage: it renders a visual of a G-code plan, a loaded mesh, or even raw G-code text, so you can catch a broken spiral, an off-bed move, or a heightmap that came out inverted before the export node writes a file.

What it takes

Everything is optional except a small settings_json (with view_mode and preview_size), because this node is designed to accept whatever you have. Give it:

  • a plan (MKR_GCODE_PLAN) - from MKRGCodeSpiralVase, MKRGCodeHeightmapPlate, or the parsed output of MKRGCodeExternalSlicer;
  • a mesh (MKR_GCODE_MESH) - from MKRGCodeLoadMeshModel;
  • raw gcode_text or a gcode_path - G-code from anywhere, not just this pack;
  • a profile - optional, used to interpret raw G-code when no plan is connected.

view_mode defaults to auto, which picks the best render from what's connected: a plan alone gets a top-down path view, a mesh alone gets an isometric wireframe, and a plan plus a mesh gets a split view (plan on the left, isometric mesh on the right). Force plan_top, mesh_top, mesh_isometric, or split if you want a specific one.

The neat part: it parses raw G-code

If you connect gcode_text (or point gcode_path at a .gcode file) with no plan, the node parses it into a plan on the fly - tracking X/Y/Z/E, G90/G91 modes, feed rates, and layer comments - and renders that. That means you can paste in G-code that a different slicer produced and still get a preview plus a usable plan output for the analyzer. This is the node's hidden superpower: it makes external G-code a first-class citizen of the lane.

Outputs

  • preview (IMAGE) - the rendered view.
  • preview_info_json - which mode rendered, plan stats, mesh triangle count, whether G-code was loaded, and warnings.
  • summary - one line about what you're looking at.
  • plan - the pass-through or parsed MKR_GCODE_PLAN, so preview can sit inline and hand the plan onward.

Installing it

Part of the pack:

# ComfyUI Manager: search "MKRShift Nodes", install, restart.
# or:
cd ComfyUI/custom_nodes
git clone https://github.com/criskb/MKRShift_Nodes
# restart ComfyUI

No extra dependencies.

Gotchas

If nothing useful is connected, you get a blank placeholder and a warning in preview_info_json - it won't crash, it'll just show you an empty box. So if your preview looks like nothing, the first place to look is the warning field, not the renderer.

Two rendering facts worth knowing. The plan render is a top view, so it's great for catching XY problems (travels crossing the part, off-bed moves) but tells you nothing about Z - an inverted heightmap that prints as a valley instead of a relief looks identical from above. Check preview_info_json's plan stats for layer count to catch gross Z mistakes. And the split mode renders the original mesh beside the toolpath, so you can compare what you asked for against what the path actually does - the single most useful check in this whole lane, and the reason to keep both inputs connected when you can.

CategoryMKRShift Nodes/G-code/Preview

Inputs (6)

NameTypeDefaultDescription
settings_jsonSTRING{"view_mode":"auto","preview_size":768}
planoptMKR_GCODE_PLAN
meshoptMKR_GCODE_MESH
profileoptMKR_GCODE_PROFILE
gcode_textoptSTRING
gcode_pathoptSTRING

Outputs (4)

NameTypeDescription
previewIMAGE
preview_info_jsonSTRING
summarySTRING
planMKR_GCODE_PLAN