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.2.0.tar.gz (237.4 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.2.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gcode_viewer-0.2.0.tar.gz
  • Upload date:
  • Size: 237.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 cf3da4751f372ff48fa203d1c2a9e648a42bcb2812cab7946212fda2c02a8a56
MD5 2746de337a9ea61f244c31b95f865f5d
BLAKE2b-256 2eafae4b0fae3dd86ca86f90fdd65f758610ce5b3e0418b27f9cc06370fd7649

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcode_viewer-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: gcode_viewer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.8 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be1b7067665859d51a30b09203674f5c08e3323ed9c6321188fb4a45c193192b
MD5 65c06f9904dfbc09f729701b5c5f2e2f
BLAKE2b-256 28a39325f4a20e5b5b7105558da7bbd3b0b96b9a8ee97959ee08340ada3023ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcode_viewer-0.2.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