Skip to main content

3D G-code toolpath viewer with interactive GUI and CLI export

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcode_viewer-0.1.0.tar.gz (237.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcode_viewer-0.1.0-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file gcode_viewer-0.1.0.tar.gz.

File metadata

  • Download URL: gcode_viewer-0.1.0.tar.gz
  • Upload date:
  • Size: 237.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gcode_viewer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a7065a6e8b0773a42413bb7d78d25624778c5c61387619358c17a3fa4465571
MD5 ba68f56de7476e7d1c77901e99d9ecdb
BLAKE2b-256 43f53f4a149c628021f6657c37dbe7075ec50f4a248ace3d0e41b29d41594e23

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcode_viewer-0.1.0.tar.gz:

Publisher: publish.yml on hyiger/gcode-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gcode_viewer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gcode_viewer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gcode_viewer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a21edf7782a6ce8fb41397d909813e0052fde128c7a44595a21215481dba425
MD5 f9a8beaa0c545ad062f258c6d5676281
BLAKE2b-256 0dcad577de2723fd628a1caf2e8347afc89dfcd4a1f9b1346d2c90bd956e5b1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcode_viewer-0.1.0-py3-none-any.whl:

Publisher: publish.yml on hyiger/gcode-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page