Skip to main content

gcode-viewer

3D G-code toolpath viewer with interactive GUI and CLI PNG export. Supports .gcode and .bgcode files via gcode-lib.

3DBenchy toolpath visualization

Features

  • Interactive 3D visualization with layer-by-layer slider
  • 6 color modes: feature type, height, speed, fan speed, temperature, volumetric flow
  • Static PNG export for batch/CI workflows
  • 4 camera presets (isometric, top, front, side) + custom azimuth/elevation
  • PrusaSlicer TYPE comment parsing for feature-type coloring
  • Auto-detected bed dimensions with grid overlay

Installation

Requires Python >= 3.10 and uv.

uv sync

Note: gcode-lib >= 1.1.0 is required. Install it editable if developing locally:

uv pip install -e /path/to/gcode-lib

Usage

Interactive GUI

gcode-viewer model.gcode

Keyboard shortcuts:

Key Action
1 Isometric camera
2 Top-down camera
3 Front camera
4 Side camera
T Toggle travel moves
V Cycle color mode
S Save screenshot

CLI Export

# Basic export
gcode-viewer model.gcode --export output.png

# Custom options
gcode-viewer model.gcode -e output.png \
  --camera front \
  --layer 50 \
  --resolution 2560x1440 \
  --color-mode height \
  --show-travel \
  --no-bed

# Custom camera angle
gcode-viewer model.gcode -e output.png \
  --camera-azimuth 45 --camera-elevation 30

CLI Options

Option Default Description
--export, -e — Export PNG and exit
--camera, -c isometric Camera preset: isometric, top, front, side
--camera-azimuth — Custom azimuth (degrees)
--camera-elevation — Custom elevation (degrees)
--layer, -l all Maximum layer to display
--resolution, -r 1920x1080 Export resolution (WxH)
--show-travel off Show travel moves
--no-bed off Hide print bed
--color-mode feature feature, height, speed, fan, temperature, flow

Architecture

G-code file
    |
    v
extractor.py  -- gcode-lib parsing --> ToolpathData (layers of Segments)
    |
    v
renderer.py   -- PyVista scene     --> per-layer actors (visibility toggle)
    |
    v
gui.py / cli.py                    --> interactive viewer or PNG export

Key design: one PyVista actor per layer enables fast layer slider updates via visibility toggling — no geometry rebuild needed. Color mode changes recolor cell data in-place.

Testing

# Unit tests (fast, ~2s)
uv run pytest -m "not integration"

# With coverage
uv run pytest -m "not integration" --cov=gcode_viewer --cov-report=term-missing

# Integration tests (requires benchy gcode file, ~12min)
uv run pytest -m integration

# Full suite
uv run pytest --cov=gcode_viewer

Project Structure

src/gcode_viewer/
  __init__.py       # version
  __main__.py       # python -m entry point
  types.py          # ExtrusionType, ColorMode, Segment, LayerData, ToolpathData
  extractor.py      # G-code parsing via gcode-lib
  colors.py         # color palettes, gradients, legend labels
  camera.py         # camera preset calculations
  bed.py            # bed plane, grid, border geometry
  renderer.py       # PyVista scene assembly & recoloring
  gui.py            # interactive viewer (PyVista + Qt)
  cli.py            # argparse + export entry point
tests/
  conftest.py       # shared fixtures
  test_*.py         # unit & integration tests

Dependencies

  • gcode-lib — G-code parsing, arc linearization, volume detection
  • PyVista — 3D mesh visualization and off-screen rendering
  • NumPy — array operations
  • PyQt6 — GUI framework

Metadata

Release files for gcode-viewer 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gcode-viewer 0.2.0
File Size Uploaded
gcode_viewer-0.2.0.tar.gz 237.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gcode-viewer 0.2.0
File Interpreter ABI Platform
gcode_viewer-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 269.2 kB

Release files / gcode_viewer-0.2.0.tar.gz

Download URL gcode_viewer-0.2.0.tar.gz
Size 237.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cf3da4751f372ff48fa203d1c2a9e648a42bcb2812cab7946212fda2c02a8a56
BLAKE2b-256 checksum
How to use checksums
2eafae4b0fae3dd86ca86f90fdd65f758610ce5b3e0418b27f9cc06370fd7649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 16, 2026.

Transparency log

Release files / gcode_viewer-0.2.0-py3-none-any.whl

Download URL gcode_viewer-0.2.0-py3-none-any.whl
Size 31.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be1b7067665859d51a30b09203674f5c08e3323ed9c6321188fb4a45c193192b
BLAKE2b-256 checksum
How to use checksums
28a39325f4a20e5b5b7105558da7bbd3b0b96b9a8ee97959ee08340ada3023ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page