docs: cad-mcp-aec.md 跟进配置改动(mcp_config.json / add_aec_* 命名) #114

Merged
gjm merged 2 commits from company-desktop/company-desktop-computer/feat-cad-mcp-aec-config AGit into main 2026-10-29 22:32:43 +08:00
5 changed files with 1833 additions and 184 deletions

No files matched your search

@@ -43,7 +43,7 @@ bool applyPipe(AecDbEwPipe* p, const nlohmann::json& a, bool bCreate, std::wstri
if (bCreate && (!bHasS || !bHasE))
{
err = L"create_aec_pipe 需要 start / end({\"x\",\"y\",\"z\"} 或 [x,y,z])";
err = L"add_aec_pipe 需要 start / end({\"x\",\"y\",\"z\"} 或 [x,y,z])";
return false;
}
@@ -92,7 +92,7 @@ bool applyPipe(AecDbEwPipe* p, const nlohmann::json& a, bool bCreate, std::wstri
{
if (dDn <= 0.0)
{
err = L"create_aec_pipe 需要 dn_mm(公称直径,mm)";
err = L"add_aec_pipe 需要 dn_mm(公称直径,mm)";
return false;
}
// 与 BZGDDlg 一致:截面圆用 DN(米制)
@@ -109,8 +109,12 @@ bool applyPipe(AecDbEwPipe* p, const nlohmann::json& a, bool bCreate, std::wstri
pX->SetAt(PIPE_SYS, wstrOr(a, "system", L"").c_str());
if (hasKey(a, "material"))
pX->SetAt(PIPE_MATERIAL, wstrOr(a, "material", L"").c_str());
if (hasKey(a, "color_index"))
pX->SetAt(_T("COLOR"), intOr(a, "color_index", 0));
// 颜色:与 cad_mcp_plugins 的既有工具统一用 color(ACI,256=ByLayer),
// 同时兼容旧写法 color_index
if (hasKey(a, "color"))
pX->SetAt(_T("COLOR"), intOr(a, "color", 256));
else if (hasKey(a, "color_index"))
pX->SetAt(_T("COLOR"), intOr(a, "color_index", 256));
return true;
}
@@ -124,7 +128,7 @@ bool applyWall(AecDbXWall* p, const nlohmann::json& a, bool bCreate, std::wstrin
if (bCreate && (!bHasS || !bHasE))
{
err = L"create_aec_wall 需要 start / end";
err = L"add_aec_wall 需要 start / end";
return false;
}
if (bHasS && bHasE)
@@ -176,7 +180,7 @@ bool applySlab(AecDbXSlab* p, const nlohmann::json& a, bool bCreate, std::wstrin
if (bCreate && !bHasPts)
{
err = L"create_aec_slab 需要 points:[[x,y],...](至少 3 个点,可不闭合)";
err = L"add_aec_slab 需要 points:[[x,y],...](至少 3 个点,可不闭合)";
return false;
}
@@ -196,7 +200,7 @@ bool applySlab(AecDbXSlab* p, const nlohmann::json& a, bool bCreate, std::wstrin
const double dElev = numOr(a, "bottom_elevation", 0.0);
if (bCreate && dThick <= 0.0)
{
err = L"create_aec_slab 需要 thickness(板厚)> 0";
err = L"add_aec_slab 需要 thickness(板厚)> 0";
return false;
}
@@ -275,7 +279,7 @@ bool applyColumn(AecDbColumn* p, const nlohmann::json& a, bool bCreate, std::wst
|| hasKey(a, "width") || hasKey(a, "rotation_deg");
if (bCreate && !bHasPos)
{
err = L"create_aec_column 需要 position(柱底中心点)";
err = L"add_aec_column 需要 position(柱底中心点)";
return false;
}
@@ -314,7 +318,7 @@ bool applyBeam(AecDbBeam* p, const nlohmann::json& a, bool bCreate, std::wstring
if (bCreate && (!bHasS || !bHasE))
{
err = L"create_aec_beam 需要 start / end";
err = L"add_aec_beam 需要 start / end";
return false;
}
if (bHasS && bHasE)
@@ -365,8 +369,13 @@ nlohmann::json finishCreate(AcDbEntity* pEnt, const nlohmann::json& a, const cha
}
}
// space:与 cad_mcp_plugins 的 add_* 工具一致,缺省模型空间
std::wstring sSpace;
if (hasKey(a, "space"))
sSpace = wstrOr(a, "space", L"");
AcDbObjectId idNew;
Acad::ErrorStatus es = addToSpace(pEnt, &idNew);
Acad::ErrorStatus es = addToSpace(pEnt, &idNew, sSpace);
// 句柄要**入图之后**才有值:append 之前 pEnt 还没 handle,取出来是 "0"
const std::string sHandle = (es == Acad::eOk) ? handleOf(pEnt) : std::string();
@@ -436,7 +445,7 @@ nlohmann::json finishUpdate(AcDbObject* pObj, const std::string& sHandle, const
class ToolCreatePipe : public mcp_Tool
{
public:
std::string private_name() const override { return "create_aec_pipe"; }
std::string private_name() const override { return "add_aec_pipe"; }
std::string private_description() const override
{
@@ -457,7 +466,7 @@ public:
"wall_thickness_mm": { "type": "number", "description": "壁厚,毫米(缺省不改)" },
"system": { "type": "string", "description": "管道系统名,如 给水/排水" },
"material": { "type": "string", "description": "材质名" },
"color_index": { "type": "integer", "description": "颜色索引(AutoCAD 颜色号)" },
"color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" },
"layer": { "type": "string", "description": "图层名,留空用当前图层" }
},
"required": [ "start", "end", "dn_mm" ]
@@ -506,7 +515,7 @@ public:
"wall_thickness_mm": { "type": "number", "description": "新壁厚,毫米(可选)" },
"system": { "type": "string", "description": "管道系统名(可选)" },
"material": { "type": "string", "description": "材质(可选)" },
"color_index": { "type": "integer", "description": "颜色索引(可选)" }
"color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer(可选)" }
},
"required": [ "handle" ]
})");
@@ -539,7 +548,7 @@ EXPORT_MCP_TOOL(ToolUpdatePipe, UpdateAecPipeTool)
class ToolCreateWall : public mcp_Tool
{
public:
std::string private_name() const override { return "create_aec_wall"; }
std::string private_name() const override { return "add_aec_wall"; }
std::string private_description() const override
{
@@ -638,7 +647,7 @@ EXPORT_MCP_TOOL(ToolUpdateWall, UpdateAecWallTool)
class ToolCreateSlab : public mcp_Tool
{
public:
std::string private_name() const override { return "create_aec_slab"; }
std::string private_name() const override { return "add_aec_slab"; }
std::string private_description() const override
{
@@ -736,7 +745,7 @@ EXPORT_MCP_TOOL(ToolUpdateSlab, UpdateAecSlabTool)
class ToolCreateColumn : public mcp_Tool
{
public:
std::string private_name() const override { return "create_aec_column"; }
std::string private_name() const override { return "add_aec_column"; }
std::string private_description() const override
{
@@ -833,7 +842,7 @@ EXPORT_MCP_TOOL(ToolUpdateColumn, UpdateAecColumnTool)
class ToolCreateBeam : public mcp_Tool
{
public:
std::string private_name() const override { return "create_aec_beam"; }
std::string private_name() const override { return "add_aec_beam"; }
std::string private_description() const override
{
@@ -91,8 +91,9 @@ nlohmann::json paramsOf(AcDbEntity* pEnt, const std::string& sType)
if (pX->GetAt(PIPE_SYS, s)) p["system"] = acharToUtf8(s);
if (pX->GetAt(PIPE_MATERIAL, s)) p["material"] = acharToUtf8(s);
// 与入参统一用 color(ACI);老字段名 color_index 不再输出
int nClr = 0;
if (pX->GetAt(_T("COLOR"), nClr)) p["color_index"] = nClr;
if (pX->GetAt(_T("COLOR"), nClr)) p["color"] = nClr;
}
}
else if (sType == kTypeWall)
@@ -188,7 +189,7 @@ nlohmann::json summaryOf(AcDbEntity* pEnt)
class ToolListAecEntities : public mcp_Tool
{
public:
std::string private_name() const override { return "list_aec_entities"; }
std::string private_name() const override { return "query_aec_entities"; }
std::string private_description() const override
{
@@ -286,7 +287,7 @@ EXPORT_MCP_TOOL(ToolListAecEntities, ListAecEntitiesTool)
class ToolGetAecEntity : public mcp_Tool
{
public:
std::string private_name() const override { return "get_aec_entity"; }
std::string private_name() const override { return "get_aec_entity_detail"; }
std::string private_description() const override
{
@@ -1,119 +0,0 @@
{
"_comment": [
"cad_mcp_aec 的工具描述。合到部署目录的 cad-mcp-frame.json 的 tools 数组里即可用(append)。",
"没有写 inputSchema:插件里的 mcp_Tool::private_input_schema() 已经带了完整 schema,",
"配置里留空时框架会自动回落到它(见 inc/mcp_plugin_api.h 的 ToLLM())。",
"dll_name 与 cad_mcp_frame.arx 同目录(plugin_directory = \".\")。"
],
"version": "1.0.0",
"tools": [
{
"name": "list_aec_entities",
"description": "列出当前图纸里本插件支持的 Envi3D 自定义实体(管道/墙/板/柱/梁),返回 handle、类型、图层、起终点、包围盒。改图之前先用它拿 handle。type 可选 all/pipe/wall/slab/column/beam,limit/offset 分页。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "ListAecEntitiesTool"
}
},
{
"name": "get_aec_entity",
"description": "按 handle 取单个 Envi3D 实体的详细参数:类型、图层、起终点、包围盒,以及该类型的关键尺寸(管道 DN/外径/壁厚;墙 厚/高/底标高/对齐;板 厚/底标高;柱 高/截面/转角;梁 截面)。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "GetAecEntityTool"
}
},
{
"name": "create_aec_pipe",
"description": "新建 Envi3D 管道(AecDbEwPipe):给起点、终点和公称直径,可选外径/壁厚/系统/材质/颜色/图层。坐标用图纸单位,dn_mm/od_mm/wall_thickness_mm 用毫米。返回新实体的 handle。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "CreateAecPipeTool"
}
},
{
"name": "update_aec_pipe",
"description": "修改已有管道:只传要改的字段(起终点、DN、外径、壁厚、系统、材质、颜色),未传的保持原值。改 DN 会重建截面,改起终点会重算几何。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "UpdateAecPipeTool"
}
},
{
"name": "create_aec_wall",
"description": "新建 Envi3D 墙体(AecDbXWall):沿 start→end 建墙,给墙厚、墙高、墙底标高,align 控制墙厚在基线哪一侧(left/center/right)。尺寸用图纸单位。返回 handle。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "CreateAecWallTool"
}
},
{
"name": "update_aec_wall",
"description": "修改已有墙体:只传要改的字段(起终点、墙厚、墙高、底标高、对齐、材质)。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "UpdateAecWallTool"
}
},
{
"name": "create_aec_slab",
"description": "新建 Envi3D 板/底板(AecDbXSlab):points 是水平轮廓点串 [[x,y],...](至少 3 点,可不闭合),给板厚与板底标高(图纸单位),center 可指定位置参考点。返回 handle。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "CreateAecSlabTool"
}
},
{
"name": "update_aec_slab",
"description": "修改已有板:传 points 会重做轮廓,否则只改板厚/板底标高/材质。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "UpdateAecSlabTool"
}
},
{
"name": "create_aec_column",
"description": "新建矩形柱(AecDbColumn):position 是柱底中心点,给柱高、截面长、截面宽,可选绕 Z 轴转角(度)。尺寸用图纸单位。返回 handle。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "CreateAecColumnTool"
}
},
{
"name": "update_aec_column",
"description": "修改已有柱:只传要改的字段(位置、柱高、截面长宽、转角、材质)。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "UpdateAecColumnTool"
}
},
{
"name": "create_aec_beam",
"description": "新建梁(AecDbBeam):沿 start→end 建梁,给截面宽与高(图纸单位)。返回 handle。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "CreateAecBeamTool"
}
},
{
"name": "update_aec_beam",
"description": "修改已有梁:只传要改的字段(起终点、截面宽高、材质)。",
"backend": {
"type": "c++_dll",
"dll_name": "cad_mcp_aec.dll",
"factory_function": "UpdateAecBeamTool"
}
}
]
}
File diff suppressed because it is too large. Load diff
+64 -45
View File
@@ -13,9 +13,9 @@ SourceCode/Code2026/cad_mcp_aec/
├── StdAfx.h / StdAfx.cpp 与 cad_mcp_plugins 同款 MFC 预处理头
├── mcp_aec.cpp 入口:EXPORT_MCP_PLUGIN_VERSION()(导出 SDK 版本数据符号)
├── aec_mcp_common.h/.cpp 参数解析、handle<->ObjectId、文档锁、结果信封
├── aec_mcp_entity_tools.cpp 5 个 create_* + 5 个 update_*
├── aec_mcp_query.cpp list_aec_entities / get_aec_entity
└── cad-mcp-aec.json 工具描述(合到运行期 cad-mcp-frame.json 的 tools 数组里)
├── aec_mcp_entity_tools.cpp 5 个 add_aec_* + 5 个 update_aec_*
├── aec_mcp_query.cpp query_aec_entities / get_aec_entity_detail
└── mcp_config.json 运行期配置(28 个既有工具 + 本插件的 12 个,cad_mcp_frame 直接读)
```
顶层 `cmakelists.txt` 里挂在 `cad_mcp_frame` 同一处:
@@ -46,15 +46,18 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20)
## 3. 工具清单(12 个)
工具名和参数都按仓库既有工具的写法(`add_line` / `query_entities` / `get_entity_detail`):
**动词_名词、点用 `[x,y]` 或 `[x,y,z]` 数组、颜色用 `color`(ACI,256=ByLayer)**。
| 工具 | 作用 | 关键参数 |
| --- | --- | --- |
| `list_aec_entities` | 列出管道/墙/板/柱/梁(handle、类型、图层、起终点、包围盒) | `type`(all/pipe/wall/slab/column/beam)、`space`、`limit`、`offset` |
| `get_aec_entity` | 按 handle 取详细参数 | `handle` |
| `create_aec_pipe` / `update_aec_pipe` | 建/改管道(`AecDbEwPipe`) | `start`/`end`、`dn_mm`、`od_mm`、`wall_thickness_mm`、`system`、`material`、`color_index`、`layer` |
| `create_aec_wall` / `update_aec_wall` | 建/改墙(`AecDbXWall`) | `start`/`end`、`thickness`、`height`、`bottom_elevation`、`align`(left/center/right) |
| `create_aec_slab` / `update_aec_slab` | 建/改板(`AecDbXSlab`) | `points`([[x,y],...])、`thickness`、`bottom_elevation`、`center` |
| `create_aec_column` / `update_aec_column` | 建/改柱(`AecDbColumn`) | `position`、`height`、`length`、`width`、`rotation_deg` |
| `create_aec_beam` / `update_aec_beam` | 建/改梁(`AecDbBeam`) | `start`/`end`、`width`、`height` |
| `query_aec_entities` | 列出管道/墙/板/柱/梁(handle、类型、图层、起终点、包围盒),分页 | `type`(all/pipe/wall/slab/column/beam)、`space`、`limit`、`offset` |
| `get_aec_entity_detail` | 按 handle 取详细参数 | `handle` |
| `add_aec_pipe` / `update_aec_pipe` | 建/改管道(`AecDbEwPipe`) | `start`/`end`、`dn_mm`、`od_mm`、`wall_thickness_mm`、`system`、`material`、`color`、`layer`、`space` |
| `add_aec_wall` / `update_aec_wall` | 建/改墙(`AecDbXWall`) | `start`/`end`、`thickness`、`height`、`bottom_elevation`、`align`(left/center/right) |
| `add_aec_slab` / `update_aec_slab` | 建/改板(`AecDbXSlab`) | `points`([[x,y],...])、`thickness`、`bottom_elevation`、`center` |
| `add_aec_column` / `update_aec_column` | 建/改柱(`AecDbColumn`) | `position`、`height`、`length`、`width`、`rotation_deg` |
| `add_aec_beam` / `update_aec_beam` | 建/改梁(`AecDbBeam`) | `start`/`end`、`width`、`height` |
**单位约定**(写进了每个工具的 description):
@@ -62,7 +65,7 @@ if (IS_ZWCAD OR CAD_SDK_VERSION GREATER_EQUAL 20)
- 管道的 `dn_mm` / `od_mm` / `wall_thickness_mm` 用 **mm**,内部按 `AS_MUNIT` 转米,
与仓库里所有管道对话框(`BZGDDlg`、`AecPipeLineTool`)一致。
**返回值**:统一 `{"ok":true, "type":..., "handle":...}`;错误是 MCP 的 error 信道
**返回值**:统一 `{"ok":true, "type":..., "handle":...}`;错误走 MCP 的 error 信道
(`-32001` 参数非法 / `-32002` 找不到 / `-32004` 类型不对 / `-32603` 内部错误)。
**update_\*** 只改传入的字段,其余保持原值;管道只给一个端点时,另一端沿用实体现有端点。
@@ -78,7 +81,7 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
### 4.2 只读实体上取专业数据必须 `kForRead`
`GetSpecialtyData()` 的**缺省参数是 `AcDb::kForWrite`**。
`get_aec_entity` 里实体是按 `kForRead` 打开的,第一次实现没注意,**直接把 acad 崩了**
`get_aec_entity_detail` 里实体是按 `kForRead` 打开的,第一次实现没注意,**直接把 acad 崩了**
(`%TEMP%\acminidump.dmp`)。现在统一写 `GetSpecialtyData(AcDb::kForRead)`。
`AecDbEwPipeBase.h` 的注释里也写着同样的话("在 draw2/3d 中使用必须 kForRead,否则图不能保存")。
@@ -96,20 +99,21 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
## 5. 端到端实测(AutoCAD 2020 / R230 Debug)
做法:临时把 `cad-mcp-aec.json` 的 12 个工具合进部署目录的 `cad-mcp-frame.json`
(备份原文件,测完还原),用 `/b` 脚本加载 `cad_mcp_frame.arx`,然后用裸 socket 打 JSON-RPC。
做法:把仓库里的 `mcp_config.json`(既有工具 + 本插件 12 个)拷到部署目录,
用 `/b` 脚本加载 `cad_mcp_frame.arx`,然后用裸 socket 打 JSON-RPC。
`%TEMP%\mcp_plugin_load.log` 里 12 个 `add_aec_*` / `update_aec_*` 工厂都是 `[try ] ... create=... destroy=...` 成功。
| 用例 | 结果 |
| --- | --- |
| `tools/list` | ✅ 返回 **30** 个工具(原 18 + 新增 12),`create_aec_pipe` 等描述可见 |
| `list_aec_entities` | ✅ pcf_1.dwg 里列出 20 根管道,handle/图层/起终点/包围盒正确 |
| `create_aec_pipe` | ✅ 返回 handle `3A0`,起点(0,0,0)→终点(2000,0,0) |
| `get_aec_entity` | ✅ 读回 `dn_mm=100 / od_mm=114 / wall_thickness_mm=4` |
| `tools/list` | ✅ 返回 **30** 个工具(原 18 + 新增 12),`add_aec_pipe` 等描述可见 |
| `query_aec_entities` | ✅ pcf_1.dwg 里列出 20 根管道,handle/图层/起终点/包围盒正确 |
| `add_aec_pipe`(点位用 `[x,y,z]`、颜色用 `color`) | ✅ 返回 handle `3A0`,起点(0,0,0)→终点(2000,0,0),`color=1` 读回一致 |
| `get_aec_entity_detail` | ✅ 读回 `dn_mm=100 / od_mm=114 / wall_thickness_mm=4` |
| `update_aec_pipe` | ✅ 改 `dn_mm=150` + 只给 `end`:终点变 3000,**壁厚仍是 4**(4.3 的修复生效) |
| `create_aec_wall` | ✅ `3A1`;get 读回 thickness=200 / height=3000 / align=center |
| `create_aec_column` | ✅ `3A2`;get 读回 height=3000 / length=400 / width=400 |
| `create_aec_beam` | ✅ `3A3`;get 读回 width=300 / height=500 |
| `create_aec_slab` | ✅ `3A0`;get 读回 thickness=100 / bottom_elevation=-500 / material=钢筋混凝土 |
| `add_aec_wall` | ✅ `3A1`;get 读回 thickness=200 / height=3000 / align=center |
| `add_aec_column` | ✅ `3A2`;get 读回 height=3000 / length=400 / width=400 |
| `add_aec_beam` | ✅ `3A3`;get 读回 width=300 / height=500 |
| `add_aec_slab` | ✅ `3A0`;get 读回 thickness=100 / bottom_elevation=-500 / material=钢筋混凝土 |
| `update_aec_slab`(只改厚度/标高) | ✅ 150 / -300 都生效 |
| 类型不匹配 | ✅ `update_aec_wall` 传板的 handle → `-32004`「实体是 XSlab,不是 AecDbXWall」 |
| 不存在的 handle | ✅ `-32002` |
@@ -117,35 +121,50 @@ MCP 工具是通过 `PostMessage` 在主线程的消息里跑的,**不在命
导出表(`dumpbin -exports cad_mcp_aec.dll`):12 个 `Create*/Update*` 工厂 + `Destroy_*`
+ `g_mcpPluginApiVersion` 全部在。
## 6. 部署与启用
## 6. 配置与启用
1. 编译:`cmake --build --preset R230 --config Debug --target CadMcpAec`
→ `cad_mcp_aec.dll` 随 Debug 构建自动部署到 `c:\ShangHuaSoft\Envi3D-2026-M\R230\`
(与 `cad_mcp_frame.arx` 同目录,`plugin_directory` 是 `"."`)。
2. 把 `cad-mcp-aec.json` 里的 `tools` 追加到部署目录的 `cad-mcp-frame.json`:
工具描述统一放 `SourceCode/Code2026/cad_mcp_aec/mcp_config.json`(与仓库既有工具同一个文件),
每个 `tool` 对象就是标准 MCP 协议字段 + `backend`:
```python
python - <<'EOF'
import json
cfg = json.load(open('cad-mcp-frame.json', encoding='utf-8'))
add = json.load(open('cad-mcp-aec.json', encoding='utf-8'))
names = {t['name'] for t in cfg['tools']}
cfg['tools'] += [t for t in add['tools'] if t['name'] not in names]
json.dump(cfg, open('cad-mcp-frame.json','w',encoding='utf-8'), ensure_ascii=False, indent='\t')
EOF
```
```json
{
"name": "add_aec_pipe",
"description": "...",
"inputSchema": { "type": "object", "properties": { ... }, "required": [ ... ] },
"backend": { "type": "c++_dll", "dll_name": "cad_mcp_aec.dll",
"factory_function": "CreateAecPipeTool" }
}
```
`cad-mcp-aec.json` 里**故意不写 `inputSchema`**:插件里
`mcp_Tool::private_input_schema()` 已经带了完整 schema,配置留空时框架会自动回落
(`inc/mcp_plugin_api.h` 的 `ToLLM()`)。这样描述与代码不会漂移。
3. 重启 CAD(或 `/reload`),`tools/list` 里应能看到 12 个 `*_aec_*` 工具。
`factory_function` 对应 DLL 里 `EXPORT_MCP_TOOL(ToolClass, FactoryName)` 导出的
`FactoryName` / `Destroy_FactoryName`;框架按 `plugin_directory`("."=arx 同目录)
拼出 `dll_name` 再 `LoadLibrary`。
启用两步:
1. 编译(Debug 会自动部署 DLL):
`cmake --build --preset R230 --config Debug --target CadMcpAec`
→ `cad_mcp_aec.dll` 落到 `c:\ShangHuaSoft\Envi3D-2026-M\R230\`
2. 把 `mcp_config.json` 拷到同一个目录(`cad_mcp_frame` 优先读它,没有才回落
`cad-mcp-frame.json`),重启 CAD。
注意:`set_debug_post_build()` 只拷构建产物,**配置文件不自动部署**,需要手工拷一次。
仓库里这份 `mcp_config.json` 是"既有 28 个工具 + 本插件 12 个"的合集,
拷过去就等于全量替换。
## 7. 已知限制
- 只支持这 5 类实体;其它 `AecDb*` 返回 `-32004`。要扩就照 `aec_mcp_entity_tools.cpp`
里"一个 apply 函数 + create/update 两个壳"的写法加。
里"一个 apply 函数 + add/update 两个壳"的写法加。
- 新建实体后 `bbox` 会是 `±1e20`:自定义实体的几何要等一次 REGEN 才建出来,
`getGeomExtents` 在未绘制时返回无效值。不是错误。
- 没有事务/撤销包装:调用即改库。批量改图建议先 `list` 拿 handle,再逐条 `update`。
- 工具描述的中文来自代码里的 `private_description()`;如果最终以运行期 JSON 为准,
记得两边同步(或者干脆像现在这样只在 JSON 里写 name + description + backend)。
- 没有事务/撤销包装:调用即改库。批量改图建议先 `query_aec_entities` 拿 handle,再逐条 `update`。
- **`mcp_config.json` 里有 10 个工具在当前 `cad_mcp_plugins.dll` 里没有对应工厂函数**
(`CreateSetDrawingAreaTool`、`CreateFindCollisionsTool`、`CreateDrawRevisionCloudTool`、
`CreateAddTextTool`、`CreateAddMTextTool`、`CreateAddPolylineTool`、`CreateAddLineTool`、
`CreateAddLeaderAnnotationTool`、`CreateDeleteEntitiesTool`、`CreateSetEntityPropertiesTool`)。
这份配置来自更新一版的插件工程,而仓库里的 `cad_mcp_plugins` 只有 16 个工具,
于是这 10 个在 `tools/list` 里会被静默丢掉(实测 `tools/list` = 30 = 18 + 12)。
要补齐得先把那 10 个工具的实现补进 `cad_mcp_plugins`。
- 插件侧 `private_description()` / `private_input_schema()` 与 `mcp_config.json` 保持同文案;
**改描述时两边一起改**(配置里写了 `description` / `inputSchema` 时以配置为准)。