Skip to main content
Glama

nx12-mcp-bridge

用自然语言(AI)驱动 Siemens NX 12:建模 → 出二维图纸 → 标注公差 → 读回校验 → 编制工艺 → 导出 PDF。

本项目是 kongbaic/NX_MCP-Enhanced (作者:抖音 无趣;其原始项目为 DreamEnding/NX_MCP) 的 NX 12 适配与功能扩展分支。


架构

AI(自然语言)
  → MCP 服务器(Python sidecar)
  → Windows 命名管道
  → NX 进程内常驻的 C# Loader
  → NXOpen

核心设计:C# Loader 随 NX 启动加载并在整个会话中常驻, 不必每次执行都跑一遍 journal —— 这是相对"逐条 journal"方案最大的效率优势。

  • C# 侧:loader/NX_MCP_Loader.cs

  • Python 侧:src/nx_mcp/(certified.py 工具注册、loader_bridge.py 命令映射)

  • 构建产物:NX_MCP_Loader.dll(部署到 NX 的 startup 目录)


Related MCP server: inventor-mcp

与上游的差异

NX 12 适配(上游面向更早版本,在 NX 12 上会编译失败)

  • 修复 MirrorBody 相关 CS1061(改用保留源体的方式)

  • 修复 ShellBuilder 相关 CS1061(改用 ReplaceRules)

  • 迁移 Update.AddToDeleteList → AddObjectsToDeleteList(NX12.0.0 弃用)

新增能力(共 68 个 MCP 工具)

类别

命令

尺寸标注

nx_create_diameter_dimension(直径,轴类必需)、nx_create_radius_dimension(半径)、nx_set_dimension_value(中差显示值强制)

草图读取

nx_read_sketch(按草图局部坐标导出全部曲线,支持外部绘制的草图)

WAVE 链接

nx_create_wave_link(主模型 → 工序件固定时间戳记/提取几何链接)

图纸文字

nx_create_note(技术要求/工序文字,`

表面粗糙度

nx_create_roughness(写入符号 a1 位)

质量属性

nx_mass_properties(体积/表面积/重心/质量,密度可传,工艺材料定额用)

对称中心线

nx_create_centerline(轴类零件轴线,SymmetricalCenterlineBuilder)

DXF/DWG 导出

nx_export_dwg(进程外官方 translator,激光切割/套料用 .dxf)

角度测量

nx_measure_angle(两直线边夹角 + 锐角补角)

剖视图

nx_create_section_view(UFUN CreateSimpleSxview,剖切线 + A-A 箭头 + 剖面线,PDF 实测渲染)+ nx_add_section_segment(阶梯剖,追加割段自动转折)

删图纸视图

nx_delete_view(改图前删旧视图;剖视图连带删剖切线)

装配 / BOM

nx_list_assembly(装配树拍平 + qty 合计数量 + 跨部件属性)+ nx_export_bom_csv(CSV 明细表,含 material/drawing_no 列,Excel 直接开)+ nx_create_id_symbol(零件序号球标,与 BOM 配套)

基准符号

nx_create_datum_symbol(GD&T 基准字母框,GB/T 17851,与形状公差标注配套)

形位公差框

nx_create_gdt_frame(GD&T 特征控制框,GB/T 1182:14 种特征中文名直认 + 公差值 + 三基准字母 + Ø 公差带 + Ⓜ/Ⓛ,PDF 实测渲染)

工序卡

nx_export_process_card(OP<nn>_字段 属性模板 → 结构化工艺卡片,text/CSV 双格式,缺字段/typo 警告)

全套图纸 PDF

nx_export_pdf <路径> ALL(全部图纸页合成一个多页 PDF)

标题栏

nx_create_title_block

部件属性

nx_set_attribute / nx_list_attributes(标题栏内容来源)

读回校验

nx_list_dimensions(值+公差)、nx_list_annotations(NOTE/GDT/ROUGH)

清理

nx_delete_annotation(按 ID/名称或 note:0/dim:1)

导出

nx_export_pdf(图纸 → PDF)

三维查询

nx_measure_distance(两棱边最小距离,基于 UFUN)

选择回流

nx_get_selection(读取图形区当前选择:用户在 NX 里点面/边/体,AI 拿到 body/face 索引,

面带 made_by 特征归属;反射路由,空选择返回 count=0 事实而非报错)

面溯源

nx_face_provenance(face_index 与 nx_list_faces 同索引空间 → 特征名/类型(made_by),

点选面后 AI 直接定位生成它的特征;owner_count=0 为事实(unite 后所有权丢失)非错误)

稳定性修复

  • "保存 CGM"弹窗把 NX 卡死:含多张图纸页的部件保存时 NX 弹模态框阻塞, 管道命令会一直等到超时。已通过在保存前关闭 SaveOptions.DrawingCgmData 根治

  • 重复打开同一部件读到陈旧数据:路径分隔符归一化修复

构建

  • build.bat 增加 NXOpen.UF.dll 引用(三维测量需要 UFUN)


环境要求

  • Windows

  • Siemens NX (需 NXBIN\managed\NXOpen*.dll)

  • .NET Framework 4.x(构建用 csc.exe)

  • Python 3.x + MCP 客户端


安装与运行

# 1) 构建 Loader
cd loader && build.bat

# 2) 部署 DLL 到 NX 的 startup 目录
#    即 %USERPROFILE%\.nx_mcp_user\startup\NX_MCP_Loader.dll
#    该目录需通过 UGII_USER_DIR 环境变量被 NX 识别

# 3) 启动 NX(需带上述环境变量)
#    从开始菜单直接打开 NX 也可以

# 4) 验证管道
python pipe_smoke.py ping nx_status

MCP 配置示例(~/.workbuddy/mcp.json):

{
  "mcpServers": {
    "nx-mcp": {
      "command": "<venv>/Scripts/python.exe",
      "args": ["-m", "nx_mcp.server"],
      "cwd": "<repo>"
    }
  }
}

注意:NX 退出后管道即断开。"后台任务不跨会话/跨天存活"是 workbuddy 运行环境的限制: workbuddy 类 AI 设备接入维护本项目时,新会话需重新拉起 NX(restart_nx.ps1)。 具备本机 shell 权限的 AI 环境(如 ZCode)没有此限制,可自行检测管道并随时拉起 NX,无需人工介入。


使用要点

  1. 边索引在部件实例间不稳定(重建后会变)→ 绝不硬编码索引, 先 nx_list_edges 再按半径/长度/坐标自动筛选

  2. body_id 有两套 ID 空间:nx_list_bodies 显示 NX 日志标识(如 EXTRUDED(1)), 命令只认建模时返回的内部 ID(如 BODY_1)

  3. 图纸名/视图名不能有空格(管道按空格分词)

  4. 标题栏内容 = 部件属性:格子引用属性显示,填标题栏要用 nx_set_attribute

  5. 坐标用 {"x":..,"y":..} 字典传,传 list 会报错


已知限制

以下功能已研究但未打通,命令保留在源码中、未注册到 MCP (避免 AI 用到必失败的工具):

功能

状态

局部放大

视图/边界/标签可创建,但放大几何不渲染(UFUN 三条路线已探明,差最后一步)

图框边框线

NXOpen.Diagramming 属图表应用,不适用于制图图纸页

真实螺纹

上游亦不支持

中心线 / DWG-DXF 导出 / 剖视图 已分别于 2026-11 攻克 (nx_create_centerline、nx_export_dwg、nx_create_section_view)。

上表各项的详细调研过程(入口 API、已试组合、排除项、错误原文、下一步建议) 由维护者另行整理,欢迎开 issue 认领其中任意一项——这些是最有价值的待攻克点。

维护者档案(不入库)

代码注释与文档中提到的「受阻项调研档案」「经验总结档案」「交接清单档案」 是维护者的本地调研/交接档案,保存在仓库外(已加入 .gitignore),不随仓库分发。 提及处的章节号指向这些本地档案;需要对应内容的请开 issue 或联系维护者。


致谢

本项目是在以下开源项目基础上的 NX 12 适配与功能扩展:

感谢以上作者的开源贡献。

Siemens NX 是 Siemens 公司的注册商标。本项目仅通过公开的 NXOpen API 与 NX 交互, 不包含任何 NX 专有代码或二进制文件 —— NX 相关程序集在构建时从本机 NX 安装目录引用。


许可证

本项目整体采用 GNU General Public License v3.0(见 LICENSE)。

上游组件以 MIT License 授权,其许可与版权声明保留在 LICENSES/Upstream-MIT.txt, 不因本项目采用 GPL 而改变;接收者仍可依据 MIT 条款单独使用那些上游组件。

如需商业授权(不适用 GPLv3 的场景),请联系仓库维护者。

Available Tools

50 tools
nx_chamferC

Create a symmetric chamfer on edges of a body; default all edges.

Inputs: offset (required), body_id (required), edge_indices. Returns: object, status, message

nx_circular_patternA

Pattern a body circularly about an axis through center.

count is the total number of instances including the original (count=4 yields 4 bodies); angle is the total sweep in degrees (360.0 distributes evenly around a full circle). The original body is kept and new instances are independent bodies (NOT united); use nx_unite if merging is required.

Inputs: axis (required), angle (required), count (required), center (required), +2 more. Returns: status, message, objects

nx_close_partB

Close the active work part, optionally saving it first.

Inputs: save. Returns: status, message

nx_counterbore_holeB

Create a coaxial counterbore hole: a smaller deep through hole plus a larger shallow counterbore from the top face. Independent from nx_hole.

Inputs: center (required), body_id (required), hole_depth (required), hole_diameter (required), +3 more. Returns: object, status, message

nx_countersink_holeA

Create a coaxial countersink (conical) hole: a smaller deep through cylinder plus a conical countersink from the top face. Independent of nx_hole / nx_counterbore_hole.

Inputs: center (required), body_id (required), hole_depth (required), hole_diameter (required), +3 more. Returns: object, status, message

nx_create_diameter_dimensionA

Create a DIAMETER dimension on one edge (essential for shafts).

A linear dimension between two edges cannot express a diameter; use this for cylindrical/circular features. edge_index is the 0-based index from nx_list_edges on the given body.

Inputs: pos_x, pos_y, body_id, view_id, +4 more. Returns: status, message

nx_create_dimensionA

Create an associative linear dimension with a bilateral tolerance.

Measures the distance between two model edges (selected by their 0-based index from nx_list_edges on the given body) inside the drafting view. Default tolerance is ±0.1 mm using the BilateralTwoLines style.

Inputs: pos_x, pos_y, body_id, view_id, +6 more. Returns: status, message

nx_create_drawing_sheetB

Create a drawing sheet and place a base view of the given model view.

The part must already contain geometry for the base view to be meaningful.

Inputs: name, size, scale, model_view, +1 more. Returns: status, message

nx_create_noteA

Add technical-requirement / process text to the current drawing sheet.

Use "|" to start a new line, e.g. "技术要求|1. 未注倒角 C0.5|2. 调质 28-32HRC". Position is in sheet coordinates (mm).

Inputs: text (required), pos_x, pos_y. Returns: status, message

nx_create_partC

Create a part inside the configured workspace.

Inputs: path (required), units. Returns: part, status, message

nx_create_projected_viewB

Project a view from an existing drafting view at sheet position (x, y).

Leave parent_view_id empty to use the first drafting view on the sheet.

Inputs: x (required), y (required), name, parent_view_id. Returns: status, message

nx_create_radius_dimensionC

Create a RADIUS dimension on one edge (fillets, arcs, rounds).

edge_index is the 0-based index from nx_list_edges on the given body.

Inputs: pos_x, pos_y, body_id, view_id, +2 more. Returns: status, message

nx_create_roughnessA

Create a surface finish (roughness) symbol on the current drawing sheet.

value goes into the symbol's a1 slot - e.g. "1.6" for Ra 1.6, "3.2" for Ra 3.2. Position is in sheet coordinates (mm).

Inputs: pos_x, pos_y, value. Returns: status, message

nx_create_sketchB

Create and activate a sketch on a principal datum plane.

Inputs: name, plane. Returns: object, status, message

nx_create_title_blockB

Place a title block on the current drawing sheet.

Position is in sheet coordinates (mm); typically bottom-right, e.g. pos_x=340, pos_y=5 for an A3 landscape sheet.

Inputs: pos_x, pos_y. Returns: status, message

nx_delete_annotationA

Delete a note / dimension / GDT / roughness annotation.

Pass either its journal id or name (e.g. "LEN_120", "HANDLE R-5132"), or a "kind:index" selector: note:0, dim:1, gdt:0, rough:0 (0-based, in the order returned by nx_list_dimensions / nx_list_annotations). Useful for cleaning up test annotations that nx_undo cannot reach.

Inputs: annotation_id (required). Returns: status, message

nx_edge_blendB

Create an edge blend (fillet) on edges of a body; default all edges.

Inputs: radius (required), body_id (required), edge_indices. Returns: object, status, message

nx_export_pdfA

Export the current drawing display to a PDF file.

Pass sheet_name to display that sheet first (the export follows the current display). Use nx_list_drawing_sheets to see available sheet names.

Inputs: path (required), sheet_name. Returns: status, message

nx_export_stepB

Export the active work part as STEP inside the configured workspace.

Inputs: path (required). Returns: path, status, message

nx_extrudeC

Extrude a sketch into a new body, or subtract it from an existing target body.

Inputs: distance (required), sketch_id (required), reverse, operation, +2 more. Returns: body, status, feature, message

nx_finish_sketchC

Deactivate and finish an explicit sketch reference.

Inputs: sketch_id (required). Returns: object, status, message

nx_fit_viewA

Fit the active modeling view.

Inputs: no named parameters. Returns: status, message

nx_holeC

Create a hole on a target body (circle sketch + boolean subtract).

Inputs: depth (required), center (required), body_id (required), diameter (required), +1 more. Returns: object, status, message

nx_linear_patternA

Pattern a body linearly along X/Y/Z.

count is the total number of instances including the original (count=4 yields 4 bodies); spacing is the per-instance delta in mm. The original body is kept and new instances are independent bodies (NOT united); use nx_unite if merging is required.

Inputs: count (required), body_id (required), spacing (required), direction (required), +1 more. Returns: status, message, objects

nx_list_annotationsA

Read the non-dimension annotations of a drawing: notes, GD&T, roughness.

Each entry is prefixed by kind: "NOTE|<journal_id>|" drafting / technical-requirement text "GDT|<journal_id>||tol=|datum=,," "ROUGH|<journal_id>" surface finish symbol Use this together with nx_list_dimensions to fully understand an existing NX 2D process drawing.

Inputs: no named parameters. Returns: status, message

nx_list_attributesB

Read back all user attributes set on the part (title-block content).

Inputs: no named parameters. Returns: status, message

nx_list_bodiesB

List bodies in the active work part.

Inputs: no named parameters. Returns: status, message, objects

nx_list_dimensionsA

Read back every dimension in the part: measured size and tolerance.

Returns one entry per dimension, formatted as "<journal_id>||size=|tol=/|<tolerance_type>". Use this to verify dimensions you just created, or to READ an existing NX 2D drawing: sizes and tolerances are recovered from the model, so an agent can understand what a drawing specifies without opening the UI.

Inputs: no named parameters. Returns: status, message

nx_list_drafting_viewsA

List the drafting views on the current drawing sheet.

Inputs: no named parameters. Returns: status, message

nx_list_drawing_sheetsA

List the drawing sheets in the active part.

Inputs: no named parameters. Returns: status, message

nx_list_edgesA

Inspect every edge of a body: index, curve type, endpoints, midpoint, length, bounding box, direction and adjacent face count. Read-only.

Inputs: body_id (required). Returns: object

nx_list_facesA

Inspect every face of a body: index, tag, face type, centroid, area, normal (planar only) and adjacent edge count. Read-only.

Inputs: body_id (required). Returns: object

nx_list_featuresA

List features in the active work part.

Inputs: no named parameters. Returns: status, message, objects

nx_list_sketchesB

List sketches in the active work part.

Inputs: no named parameters. Returns: status, message, objects

nx_measure_distanceA

Measure the minimum 3D distance between two edges of a body.

This is a QUERY: no annotation is created. It returns the numeric distance (mm) plus the two closest points, so an agent can verify geometry instead of guessing. Indices are 0-based from nx_list_edges.

Inputs: body_id, edge_index_1, edge_index_2. Returns: status, message

nx_mirrorA

Mirror a body about a datum plane.

plane selects the mirror datum plane (XY/XZ/YZ); offset shifts that plane along its normal by the given mm value (default 0). The mirrored body is created as an independent body and is NOT united with the source; use nx_unite if merging is required.

Inputs: plane (required), body_id (required), offset. Returns: object, status, message

nx_open_partC

Open a part from the configured workspace.

Inputs: path (required). Returns: part, status, message

nx_releaseA

Clear the current task state and return NX to normal interaction.

With the resident C# Loader backend, the Loader and named pipe remain alive for the entire NX session; nx_release does not unload the plugin or require Alt+F8 to start it again.

Inputs: no named parameters. Returns: status, message

nx_revolveB

Revolve a closed sketch section around an in-sketch 2D axis.

Creates a new solid only (no unite/subtract). axis_start and axis_end are sketch XY coordinates defining the revolution axis; angle is the sweep angle in degrees (0 < angle <= 360).

Inputs: axis_end (required), sketch_id (required), axis_start (required), angle, +1 more. Returns: object, status, message

nx_save_partB

Save the active work part.

Inputs: no named parameters. Returns: status, message

nx_set_attributeB

Set a string attribute on the part.

This is how a title block gets its CONTENT: title-block cells usually reference part attributes. Typical names: 名称 / 图号 / 材料 / 设计 / 审核 / 比例 / 单位. Value may contain spaces.

Inputs: name (required), value (required). Returns: status, message

nx_shellA

Shell (hollow) a body: remove one face as an opening and keep a constant wall thickness. First version removes a single face; inward=True keeps the outer dimensions.

Inputs: body_id (required), thickness (required), remove_face_index (required), inward. Returns: object, status, message

nx_sketch_arcC

Add an arc (center, radius, start/end degrees) to an explicit sketch reference.

Inputs: center (required), radius (required), sketch_id (required), end_angle, +1 more. Returns: object, status, message

nx_sketch_circleC

Add a circle (center + diameter) to an explicit sketch reference.

Inputs: center (required), diameter (required), sketch_id (required). Returns: object, status, message

nx_sketch_lineC

Add a line to an explicit sketch reference.

Inputs: end (required), start (required), sketch_id (required). Returns: object, status, message

nx_sketch_rectangleC

Add a rectangle to an explicit sketch reference.

Inputs: corner1 (required), corner2 (required), sketch_id (required). Returns: status, message, objects

nx_statusA

Report bridge, NX version, and active-part status.

Inputs: no named parameters. Returns: status, connected, nx_version, active_part, +1 more

nx_undoB

Undo the last visible NX MCP operation.

Inputs: no named parameters. Returns: status, message

nx_uniteB

Boolean-unite one or more tool bodies into the target body.

The target body keeps its id; the tool bodies are consumed and disappear from nx_list_bodies after the boolean.

Inputs: tool_body_ids (required), target_body_id (required). Returns: object, status, message

nx_update_viewsA

Force every drafting view on the current sheet to a fresh update.

Clears the out-of-date ("clock") flag shown in the Part Navigator after a drawing or projected view is created or modified.

Inputs: no named parameters. Returns: status, message

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 50 tools

    Disambiguation4/5

    Most tools have clearly distinct purposes: part lifecycle, sketch creation, modeling features, booleans, drafting, annotation, attributes, queries, and export. There is some potential overlap within the hole family (nx_hole, nx_counterbore_hole, nx_countersink_hole) and dimension-creation family, but the descriptions make the boundaries reasonably clear.

    Naming Consistency4/5

    All tools use a consistent nx_ snake_case prefix, which makes the set readable and predictable. However, the names are not uniformly verb_noun: several modeling tools use feature nouns or noun-like verbs such as nx_hole, nx_shell, nx_extrude, nx_chamfer, and nx_unite.

    Tool Count2/5

    Fifty tools is very high for a single MCP server and exceeds the well-scoped range even though NX CAD/drafting is a broad domain. Many granular listing, drafting, annotation, and attribute tools are justified individually, but the overall surface is heavy enough to increase selection cost and cognitive load.

    Completeness4/5

    The surface covers a broad CAD workflow: part lifecycle, sketching, solid modeling, booleans, patterns, drafting, dimensions, annotations, attributes, measurement, and export. Remaining gaps include assembly-level operations, editing existing feature parameters, body/feature deletion beyond undo, and some dimension types, but core workflows are well supported.

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language control of Siemens NX for text-to-CAD modeling, generating .prt files via NX Open API. Currently supports basic solids, booleans, and fillets in batch mode.
      5
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables natural-language control of Autodesk Inventor to create parametric parts, sketches, holes, and sheet-metal features, and to inspect, save, or export models.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables natural-language generation and editing of native CATIA V5 parts and assemblies through MCP tools, converting semantic requests into parametric CATPart/CATProduct models via the CATIA Automation API.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to drive desktop CAD software through natural language with verified execution, failure recovery, and traceable results across modeling, assemblies, drawings, exports, motion, FEA, and related engineering workflows.
      1
      MIT