NLP-to-CAD Industrial Skill
Purpose
Convert natural language engineering descriptions into CAD models, drawings, and manufacturing data.
Execution Flow
Phase 1: Parse Intent
- Extract technical entities: dimensions, materials, tolerances, features
- Identify CAD operation type: create/modify/analyze/export
- Determine target format and units
- Map domain-specific terms to standard notation
Phase 2: Knowledge Retrieval
- Load relevant industry standards from
references/industry-knowledge/ - Fetch applicable CAD templates from
references/cad-templates/ - Match NLP patterns from
references/nlp-patterns/
Phase 2.5: 联网检索 + 三步式推荐 (Pre-generation guidance)
When the user gives only a natural-language description without full dimensions
or structure, do not generate blindly. See references/nlp-patterns/web-search-and-recommend.md
(WebSearch / WebFetch 联网搜索 → 有参考图纸则采用 → 无则三步式推荐):
1. Search the web for the object's standard/typical features (dimensions, standards, materials, structure).
2. If a reference CAD drawing / standard spec is found → use it and record the source.
3. Otherwise → three-step recommendation (类型 → 关键尺寸 → 输出内容) via AskUserQuestion, one question per step.
4. Summarize the confirmed parameters before generating.
Phase 3: Code Generation
- Select appropriate code generator based on target CAD system (see "Supported CAD Systems" below — each entry points to its own reference under
references/code-generators/. Always read the reference before writing code; the ZWCAD one in particular has multiple non-obvious pitfalls that will silently produce wrong output.) - Apply parametric constraints and dimensions
- Generate manufacturing annotations
Phase 4: DXF + PNG 预览 (Preview rendering)
After the drawing is produced, always also deliver a raster preview so users without
CAD software can see the result. See references/code-generators/dxf-png-render.md:
- Generate/export the drawing as DXF (ezdxf, or $doc.SaveAs(...dxf) from ZWCAD).
- Render part.png from the DXF with ezdxf.addons.drawing + matplotlib (Agg backend, CJK font for Chinese labels).
- Deliver part.dxf + part.png together.
Phase 5: Validation
- Syntax check for output format
- Engineering rule validation (dimensions, tolerances, materials)
- Cross-reference with industry databases
Output Contracts
CAD Model Output
Format: STEP | IGES | STL | Parasolid | ACIS | Native CAD format
Units: mm | inch
Precision: 0.001mm standard
Validation: ISO 10303 compliance
Engineering Drawing Output
Formats: PDF | DWG | DXF | PNG (raster preview)
Views: orthographic | isometric | section | detail
Annotations: GD&T per ASME Y14.5-2018
Every DXF/DWG drawing ships with a matching PNG preview (see
references/code-generators/dxf-png-render.md), so the result is viewable
without CAD software installed.
Manufacturing Data Output
CNC: G-code | M-code
Reports: BOM | Process sheet | Material specs
Supported CAD Systems
- FreeCAD (Python API)
- OpenSCAD (CSG)
- Onshape | Fusion 360 (via API)
- STEP/IGES standard exchange
- ZWCAD / 中望 CAD (Windows COM via PowerShell) — see
references/code-generators/zwcad-com.md. Use this when the target CAD is 中望 CAD Personal (Windows). Verified against ZWCAD 3.0.1 (COM Version 2025) on Windows 11 + PowerShell 5.1. Key constraint:Document.ActiveLayersetter is racy — always pass the layer explicitly and setentity.LayerafterAddLinereturns.
Error Handling
- Unclear dimension → ask for clarification with suggestions
- Invalid material → map to nearest standard grade
- Complex geometry → offer simplification or manual approach
- Unsupported format → suggest nearest equivalent
- ZWCAD-specific traps (see
references/code-generators/zwcad-com.md§4 for the full list): Utility.CreatePointdoes not exist — pass[double[]] @(x,y,z)directly.AddPolylinewith flat double array throws0x80210011— use 4×AddLinefor rectangles instead.ActiveLayersetter race — entities may land on the wrong layer. Always setentity.Layerexplicitly after creation.SendCommandblocks on wizard-style commands (_PLOT,_EXPORT,_DIMLINEAR); use COM methods ($zw.ZoomExtents(),SetVariable) instead.- Default
txt.shxfont renders CJK as garbage — create aCNtext style withsimsun.ttcand setActiveTextStylebeforeAddText. - PowerShell 5.1 parses
.ps1as ANSI — Chinese literals truncate. Use[char]0xXXXXform, or save script as UTF-8 BOM.
Example Triggers
- "设计一个法兰,直径200mm,厚度20mm,材料304不锈钢"
- "生成这个零件的工程图,标注尺寸和公差"
- "把这段描述转成STEP文件:圆柱形壳体,两端开口..."
- "创建BOM表,包含材料清单和数量"
- "这段管路设计的展开图,DN50的管道"
Integration
All heavy data lives in references/. Main file handles routing and orchestration.
Do not inline large tables, code samples, or domain knowledge—delegate to reference files.
Two new reference files drive the pre/post-generation UX:
- references/nlp-patterns/web-search-and-recommend.md — 联网检索该对象特征;有参考图纸则采用,无则三步式推荐(类型 → 尺寸 → 输出)后生成。
- references/code-generators/dxf-png-render.md — 纯 Python 生成 DXF 并渲染 PNG 预览,供无 CAD 用户查看。