科研 Skill

图像直接生成FDM G代码

image2gcode

Converts a photo, sketch, or slice image of a flat or near-flat part directly into FDM G-code without CAD, via silhouette and toolpath extraction. Use for sketch-to-print without modeling.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

Image2Gcode: image → G-code (2D / 2.5D)

Paper: Z. Wang, Y. Jadhav, P. Pak, A. Barati Farimani, Image2Gcode: Image-to-G-code generation for additive manufacturing using diffusion-transformer model, Additive Manufacturing Letters 17 (2026) 100374.

What's bundled. The paper's preprocessing, keypoint representation, post-processing and validation are reproduced exactly. The trained DDPM (DinoV2 + 1-D U-Net) is available from the authors on request. In its place, generate is a deterministic perimeter-plus-infill generator that emits the same keypoint and G-code format, so model samples drop in later (references/ddpm_hook.md). Tell the user which generator produced their toolpath.

Scope matches the paper: parts described by one cross-section, or a few layer-wise consistent ones (plates, brackets, gaskets, coasters, 2.5D extrusions). For full 3-D parts, use CAD (parametric-part-cad) and a slicer.

Setup: pip install opencv-python-headless shapely numpy matplotlib. I = scripts/i2g.py.

Workflow

  1. Preprocess the image.
    python $I preprocess sketch.jpg --out sil.png --mode sketch   # pen outline on paper
    python $I preprocess photo.jpg  --out sil.png --mode photo    # object photo on a plain background
    python $I preprocess slice.png  --out sil.png --mode slice    # already a filled cross-section
    
    Look at sil.png. White should be material and holes black. If the outline isn't closed or the background leaks in, fix the input (crop, raise contrast, close gaps) rather than tuning the toolpath.
  2. Get physical size and print settings from the user: overall size (the image has no scale), thickness (layers × layer height), nozzle and line width, infill pattern and density, temperatures, bed size. If unstated, use defaults (0.2 mm layers, 0.45 mm lines, 2 perimeters, 25% rectilinear, PLA 210/60 °C) and list them.
  3. Generate.
    python $I generate sil.png --size-mm 60 --layers 15 --infill rectilinear --density 0.25 --out part.gcode
    
  4. Validate and inspect.
    python $I validate part.gcode --bed 220 220 250
    python $I plot part.gcode --out paths.png --layers 0,1
    
    ok must be true. Check the plot: closed perimeters around every hole, infill inside the walls only, alternating raster direction between layers. Compare the reported area or bbox with the intended size.
  5. Deliver the G-code, the path plot, and a settings table, with first-print advice (preview it in the user's slicer or viewer first; the header homes and heats with standard Marlin codes).

Working with existing G-code

  • python $I keypoints any.gcode --out kp.npz builds Slice-100K-style per-layer (X, Y, E) keypoints with the paper's normalization. It handles G90/G91, M82/M83, mid-file G92 E resets, and constant-E travels. Use it for datasets, comparisons, and travel-distance studies (the paper reports a −2.40% mean travel distance against heuristic slicers).
  • python $I emit kp.npz --layer 0 --size-mm 40 --out layer.gcode denormalizes keypoints (including model samples) into G-code at any physical scale, with --flow-mult for printer-specific extrusion.

Limits

Hand-drawn wobble carries into the part, since the boundary is the drawing. Very thin features (under 2 line widths) vanish in the perimeter offset. There's no bridging or support logic, so the parts are prismatic by construction.

示例提示词

帮我把这张零件草图直接转成可打印的FDM G代码,不用建CAD模型。

所属插件

机械设计与先进制造面向机械设计与制造研究:文本/草图生成 CAD、FreeCAD/SolidWorks 参数化建模、机构综合与零件选型、公差与 GD&T、DFM 与设计评审、快速有限元与应力代理模型、增材制造工艺与缺陷预测、疲劳断裂寿命。

安装该插件会一并获得同领域的 35 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

图像直接生成FDM G代码能做什么?

Converts a photo, sketch, or slice image of a flat or near-flat part directly into FDM G-code without CAD, via silhouette and toolpath extraction. Use for sketch-to-print without modeling。

如何安装图像直接生成FDM G代码?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「图像直接生成FDM G代码」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

图像直接生成FDM G代码需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

图像直接生成FDM G代码经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。