G-code Slicing with Real Slicer CLIs and Printer Profiles: A Complete Guide

The earthtojake/text-to-cad repository provides a production-ready G-code skill that orchestrates real slicer command-line interfaces (OrcaSlicer, PrusaSlicer, CuraEngine) with validated printer profiles through a modular Python toolkit.

For teams building AI agents or automated fabrication pipelines, G-code slicing with real slicer CLIs and printer profiles requires more than abstract APIs. The text-to-cad project delivers a complete, inspectable workflow—from mesh validation through dry-run preview to validated G-code output—designed specifically for agent-driven manufacturing workflows.

Architecture Overview

The repository follows a strict separation of concerns that keeps runtime footprints minimal and agent loading fast:

Layer Location Purpose
Skill definitions skills/<skill>/SKILL.md Declarative metadata and workflow contracts
Skill runtimes skills/<skill>/scripts/ Executable Python/JS implementations
Shared libraries packages/*/ Reusable, dependency-free utilities
Viewer & assets skills/cad-viewer/, assets/, benchmarks/ Browser-based preview and demonstration material

This structure enables agents to load only required capabilities. The G-code skill itself demonstrates this pattern: its manifest lives at skills/gcode/SKILL.md while the runtime implementation resides in skills/gcode/scripts/gcode_tool.py.

The G-code Skill Implementation

The core G-code slicing capability is implemented in skills/gcode/scripts/gcode_tool.py. This script provides a unified interface to multiple slicer back-ends while enforcing profile validation at every stage.

Slicer Discovery

The tool probes system PATH and common macOS locations to locate available slicers:

python scripts/gcode_tool.py discover

This command reports detected back-ends such as orcaslicer, prusa-slicer, or curaengine. The discovery mechanism allows agent workflows to adapt to whatever slicer stack is installed on the target system.

Mesh Inspection

Before any slicing occurs, the tool validates mesh integrity:

python scripts/gcode_tool.py inspect \
  --input path/to/model.stl \
  --json

The JSON output indicates slice-readiness, bounding box dimensions, and detects obvious mesh defects that would cause slicer failures.

Profile-Driven Slicing Workflow

The G-code skill enforces a printer profile contract that makes slicing reproducible across different hardware configurations. Profiles are JSON documents specifying temperatures, speeds, acceleration limits, and machine envelopes.

Dry-Run Preview

Agents and users can review the exact CLI invocation before execution:

python scripts/gcode_tool.py slice \
  --input path/to/model.stl \
  --output /tmp/model.gcode \
  --profile path/to/profile.json \
  --backend auto \
  --dry-run

This generates the complete slicer command without running it, enabling verification of parameter mapping and path resolution.

Execute and Validate

Production slicing combines execution with automatic validation:

python scripts/gcode_tool.py slice \
  --input path/to/model.stl \
  --output /tmp/model.gcode \
  --profile path/to/profile.json \
  --backend auto \
  --execute
python scripts/gcode_tool.py validate \
  --gcode /tmp/model.gcode \
  --profile path/to/profile.json \
  --json

The validation step checks for:

  • Non-empty G-code content
  • Temperature commands matching profile specifications
  • Movement limits respecting machine envelopes
  • Extrusion moves present
  • Bounded XYZ ranges
  • Unknown command detection

Integration with CAD Viewer

Generated G-code can be handed to the CAD Viewer skill (skills/cad-viewer/) for immediate visual verification:

$cad-viewer /tmp/model.gcode

The viewer launches a browser-based interface that renders toolpaths, preview layers, and machine movements. This integration closes the loop between automated slicing and human inspection without leaving the agent workflow.

Shared Infrastructure

The repository's packages/ namespace contains language-agnostic utilities. Of particular relevance, packages/cadpy_metadata/src/cadpy_metadata/py.typed provides lightweight, dependency-free Python helpers used across multiple skills—including the G-code skill's metadata handling.

According to the source code analysis, this shared library approach ensures that skills remain composable: the G-code skill loads only what it needs, keeping cold-start times low for agent initialization.

Repository Workflow

The development workflow documented in AGENTS.md uses symlinks to maintain reproducible builds. Skills reference shared packages without duplicating code, and the runtime environment resolves these relationships at load time.

For G-code slicing deployments, this means:

  • Single source of truth for profile schemas
  • Consistent validation logic across all fabrication skills
  • Incremental updates to shared libraries without skill rewrites

Summary

  • G-code slicing with real slicer CLIs and printer profiles in text-to-cad is implemented through a dedicated skill at skills/gcode/scripts/gcode_tool.py
  • The tool supports OrcaSlicer, PrusaSlicer, and CuraEngine through automatic discovery
  • A strict profile contract ensures reproducible, machine-specific outputs
  • Dry-run mode enables safe agent preview before execution
  • Built-in validation checks G-code integrity against profile constraints
  • CAD Viewer integration provides immediate visual feedback
  • The modular architecture minimizes runtime dependencies for agent deployment

Frequently Asked Questions

What slicer back-ends does the G-code skill support?

The gcode_tool.py script discovers and supports OrcaSlicer, PrusaSlicer, and CuraEngine through system PATH scanning and common macOS installation locations. The --backend auto flag selects the preferred available option, or you can specify a particular slicer explicitly.

How does printer profile validation work?

The validation layer in skills/gcode/scripts/gcode_tool.py checks generated G-code against the supplied profile JSON for temperature commands, movement limits, acceleration settings, and machine envelope bounds. The validate subcommand produces structured JSON output suitable for automated decision-making in agent workflows.

Can I preview the slicer command without running it?

Yes. Pass --dry-run to any slice invocation. The tool outputs the complete command-line string that would be executed, including all profile-mapped parameters, without spawning the slicer process. This supports safe verification in automated pipelines.

What is the CAD Viewer and how do I use it with G-code?

The CAD Viewer is a browser-based preview skill located at skills/cad-viewer/. It launches via the $cad-viewer runtime variable and automatically renders any supported file type—including G-code toolpaths. After slicing, hand off the output with $cad-viewer /path/to/output.gcode to visualize layers, movements, and extrusion paths.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →