gcode

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

G-code

G-code

Use this skill for plain
.gcode
generation from mesh files. It is printer-agnostic and never uploads, starts, or packages print jobs.
本技能用于从网格文件生成纯
.gcode
文件。它与打印机无关,绝不会上传、启动或打包打印任务。

Workflow

工作流程

  1. Confirm the input is a supported mesh:
    .stl
    ,
    .obj
    , unsliced
    .3mf
    ,
    .ply
    ,
    .glb
    , or
    .gltf
    .
  2. Require an explicit printer/profile wrapper JSON. Do not invent real-printer profiles.
  3. Discover slicer backends when the backend is unknown:
bash
python scripts/gcode_tool.py discover
  1. Inspect the input:
bash
python scripts/gcode_tool.py inspect --input path/to/model.stl --json
  1. Dry-run the slicer command before executing:
bash
python scripts/gcode_tool.py slice \
  --input path/to/model.stl \
  --output /tmp/model.gcode \
  --profile path/to/profile.json \
  --backend auto \
  --dry-run
  1. Execute only after the dry-run command and profile are appropriate:
bash
python scripts/gcode_tool.py slice \
  --input path/to/model.stl \
  --output /tmp/model.gcode \
  --profile path/to/profile.json \
  --backend auto \
  --execute
  1. Validate the generated G-code:
bash
python scripts/gcode_tool.py validate \
  --gcode /tmp/model.gcode \
  --profile path/to/profile.json \
  --json
  1. 确认输入为支持的网格格式:
    .stl
    .obj
    、未切片的
    .3mf
    .ply
    .glb
    .gltf
  2. 需要明确的打印机/配置包装器JSON文件。请勿虚构真实打印机配置。
  3. 当后端未知时,发现切片器后端:
bash
python scripts/gcode_tool.py discover
  1. 检查输入:
bash
python scripts/gcode_tool.py inspect --input path/to/model.stl --json
  1. 在执行前试运行切片器命令:
bash
python scripts/gcode_tool.py slice \
  --input path/to/model.stl \
  --output /tmp/model.gcode \
  --profile path/to/profile.json \
  --backend auto \
  --dry-run
  1. 仅在试运行命令和配置合适后执行:
bash
python scripts/gcode_tool.py slice \
  --input path/to/model.stl \
  --output /tmp/model.gcode \
  --profile path/to/profile.json \
  --backend auto \
  --execute
  1. 验证生成的G-code:
bash
python scripts/gcode_tool.py validate \
  --gcode /tmp/model.gcode \
  --profile path/to/profile.json \
  --json

CAD Viewer Handoff

CAD Viewer 交付

After completing G-code work that creates or modifies a plain
.gcode
, you must ALWAYS hand the explicit file path to
$cad-viewer
when that skill is installed.
$cad-viewer
must start CAD Viewer if it is not already running and return link(s) to the relevant created or updated file(s); the preview is diagnostic only and does not replace this skill's static validation. If
$cad-viewer
is unavailable or startup fails, report that instead of silently omitting the handoff.
在完成创建或修改纯
.gcode
的G-code相关工作后,当
$cad-viewer
技能已安装时,必须始终将明确的文件路径传递给它。如果CAD Viewer尚未运行,
$cad-viewer
必须启动它,并返回相关已创建或更新文件的链接;预览仅用于诊断,不能替代本技能的静态验证。如果
$cad-viewer
不可用或启动失败,请报告该情况,不要静默跳过交付步骤。

Profile Contract

配置契约

Every slice requires a wrapper profile JSON with an absolute native slicer profile path:
json
{
  "backend": "orcaslicer",
  "native_config": "/absolute/path/to/native-slicer-profile",
  "machine": {
    "name": "Example Printer",
    "bed_size_mm": [180, 180],
    "z_height_mm": 180,
    "motion_bounds_mm": {
      "x": [0, 180],
      "y": [0, 180],
      "z": [0, 180]
    }
  },
  "filament": {
    "type": "PLA",
    "nozzle_temp_c": 220,
    "bed_temp_c": 65
  }
}
The wrapper supplies validation bounds and backend selection.
machine.motion_bounds_mm
is optional; omit it for the default
0..bed_size
and
0..z_height
bounds, or set it from a native printer profile when start/end G-code intentionally uses safe wipe/purge positions outside the printable area. The native slicer profile remains the source of detailed process, printer, and filament behavior.
For OrcaSlicer, use
native_settings
and
native_filaments
when the real profile is split across machine, process, and filament JSON files. Keep
native_config
as an absolute path to the primary native profile for compatibility:
json
{
  "backend": "orcaslicer",
  "native_config": "/absolute/path/to/machine-or-process.json",
  "native_settings": [
    "/absolute/path/to/machine.json",
    "/absolute/path/to/process.json"
  ],
  "native_filaments": [
    "/absolute/path/to/filament.json"
  ],
  "machine": {
    "name": "Example Printer",
    "bed_size_mm": [180, 180],
    "z_height_mm": 180
  },
  "filament": {
    "type": "PLA",
    "nozzle_temp_c": 220,
    "bed_temp_c": 65
  }
}
每次切片都需要一个包含绝对原生切片器配置路径的包装器配置JSON文件:
json
{
  "backend": "orcaslicer",
  "native_config": "/absolute/path/to/native-slicer-profile",
  "machine": {
    "name": "Example Printer",
    "bed_size_mm": [180, 180],
    "z_height_mm": 180,
    "motion_bounds_mm": {
      "x": [0, 180],
      "y": [0, 180],
      "z": [0, 180]
    }
  },
  "filament": {
    "type": "PLA",
    "nozzle_temp_c": 220,
    "bed_temp_c": 65
  }
}
这个包装器提供验证边界和后端选择。
machine.motion_bounds_mm
是可选的;如果默认边界为
0..bed_size
0..z_height
,则可省略该字段;或者当起始/结束G-code有意使用可打印区域外的安全擦拭/吹扫位置时,从原生打印机配置中设置该字段。原生切片器配置仍是详细工艺、打印机和耗材行为的来源。
对于OrcaSlicer,当真实配置分散在机器、工艺和耗材JSON文件中时,请使用
native_settings
native_filaments
。为了兼容性,将
native_config
保留为指向主原生配置的绝对路径:
json
{
  "backend": "orcaslicer",
  "native_config": "/absolute/path/to/machine-or-process.json",
  "native_settings": [
    "/absolute/path/to/machine.json",
    "/absolute/path/to/process.json"
  ],
  "native_filaments": [
    "/absolute/path/to/filament.json"
  ],
  "machine": {
    "name": "Example Printer",
    "bed_size_mm": [180, 180],
    "z_height_mm": 180
  },
  "filament": {
    "type": "PLA",
    "nozzle_temp_c": 220,
    "bed_temp_c": 65
  }
}

Backends And Inputs

后端与输入

Preferred slicer backend order is
orcaslicer
,
prusa-slicer
, then
curaengine
. Prefer installing OrcaSlicer when no preferred backend is available; on macOS use
brew install --cask orcaslicer
and then rerun
discover
. The helper checks both
PATH
and the usual
/Applications/OrcaSlicer.app
cask location. Bambu Studio may be reported by discovery as available but is not preferred because its CLI export path has shown macOS instability.
Pass
.stl
,
.obj
, and unsliced
.3mf
directly to the slicer. Convert
.ply
,
.glb
, and
.gltf
to temporary STL at execution time with optional
trimesh
; if
trimesh
is unavailable, ask the user to install it or provide
.stl
,
.obj
, or unsliced
.3mf
.
Reject
.step
,
.stp
,
.dxf
,
.svg
,
.urdf
, and
.sdf
in v1. Use the existing CAD/render workflows to convert those to a supported mesh format before using this skill.
Read
references/slicer-backends.md
when backend behavior, profile expectations, or source links matter.
首选切片器后端顺序为
orcaslicer
prusa-slicer
,其次是
curaengine
。当没有首选后端可用时,优先安装OrcaSlicer;在macOS上使用
brew install --cask orcaslicer
命令安装,然后重新运行
discover
。该工具会检查
PATH
和常用的
/Applications/OrcaSlicer.app
安装位置。Bambu Studio可能会被发现为可用后端,但并非首选,因为其CLI导出路径在macOS上存在稳定性问题。
.stl
.obj
和未切片的
.3mf
直接传递给切片器。执行时可通过可选的
trimesh
.ply
.glb
.gltf
转换为临时STL文件;如果
trimesh
不可用,请要求用户安装它或提供
.stl
.obj
或未切片的
.3mf
文件。
在v1版本中,拒绝
.step
.stp
.dxf
.svg
.urdf
.sdf
格式。在使用本技能之前,请使用现有的CAD/渲染工作流将这些格式转换为支持的网格格式。
当后端行为、配置要求或源链接很重要时,请阅读
references/slicer-backends.md

Validation

验证

Always validate generated G-code before handing it to printer-specific workflows. The validator checks for non-empty content, temperature commands, movement commands, extrusion moves, XYZ bounds, and unknown command warnings.
Read
references/gcode-validation.md
when interpreting validation output or deciding whether a warning is acceptable.
在将生成的G-code交付给特定打印机的工作流之前,始终要对其进行验证。验证器会检查内容是否非空、温度命令、移动命令、挤出移动、XYZ边界以及未知命令警告。
当解释验证输出或判断警告是否可接受时,请阅读
references/gcode-validation.md

Bambu Boundary

Bambu 边界

This skill generates plain
.gcode
only. It does not create Bambu
.gcode.3mf
archives and does not contact printers. For Bambu upload/start workflows, hand off the validated plain
.gcode
to
$bambu-labs
. Let
$bambu-labs
choose the printer-specific LAN handoff, such as an A1 Mini template project or an explicitly enabled bambox project package.
本技能仅生成纯
.gcode
文件。它不会创建Bambu
.gcode.3mf
存档,也不会与打印机通信。对于Bambu上传/启动工作流,请将经过验证的纯
.gcode
文件交付给
$bambu-labs
。让
$bambu-labs
选择特定打印机的LAN交付方式,例如A1 Mini模板项目或明确启用的bambox项目包。