现象:cad_mcp_frame 的插件机制只能挂"纯 AcDb 层"的只读工具 (cad_mcp_plugins 不链接 CoreCommand,拿不到 AecDbEwPipe / AecDbXWall / AecDbXSlab / AecDbColumn / AecDbBeam 这些类的实现),agent 没法改仓库的自定义实体。 改动:新建 SourceCode/Code2026/cad_mcp_aec,仍是普通 DLL(由 frame 运行时 LoadLibrary),但链接 CoreCommand_BAL_REMOTE(内含静态库 CoreLibrary), 因此可以 new / 修改这五类实体。cmake 照 PipelineCmd 的写法,并在顶层 cmakelists.txt 里挂在 cad_mcp_frame 同一处(C++11+ 才编,R180/R190 跳过)。 12 个工具(每个实体一个 create + 一个 update,外加 list/get): list_aec_entities / get_aec_entity create_aec_pipe / update_aec_pipe create_aec_wall / update_aec_wall create_aec_slab / update_aec_slab create_aec_column / update_aec_column create_aec_beam / update_aec_beam 单位约定:坐标与建筑尺寸用图纸单位;管道的 dn_mm / od_mm / wall_thickness_mm 用毫米,内部按 AS_MUNIT 转米(与 BZGDDlg、AecPipeLineTool 一致)。 update_* 只改传入字段;管道只给一个端点时另一端沿用实体现有值。 实现上撞到三个坑,都已修: 1. MCP 工具在主线程消息里跑、不在命令上下文,写库必须先 acDocManager->lockDocument(),否则 appendAcDbEntity 返回 eLockViolation(0x140)。用 DocLock RAII 包起来。 2. 只读实体上取专业数据必须 GetSpecialtyData(AcDb::kForRead): 该函数缺省参数是 kForWrite,第一次实现没注意,直接把 acad 崩了 (%TEMP%\acminidump.dmp)。 3. SetSection() 会清掉 PIPE_THICK 等派生字段("只改 DN"会把壁厚清成 0); AecDbXSlab::SetRegionSlab(AcGePoint2dArray&) 内部连线不补闭合点, 传点串必须自己首尾闭合。两处都按实测结果处理了。 验证方式: - R230 Debug、Z2026 Debug 两个 preset 编译通过并自动部署 (cad_mcp_aec.dll,12 个工厂函数 + g_mcpPluginApiVersion 都在导出表里)。 - AutoCAD 2020 实测(临时把工具合进部署目录的 cad-mcp-frame.json,测完还原): tools/list 返回 30 个工具;pcf_1.dwg 上 list 出 20 根管道; 五种实体各建一次并用 get 读回参数一致;管道改 DN+单端点后壁厚保留; 板改厚/标高生效;类型不匹配与非法 handle 返回 -32004 / -32002。 详见 cad-mcp-aec.md 第 5 节的用例表。 已知限制:只支持这五类实体;新建实体要等一次 REGEN 才有 bbox; 工具没有事务包装;运行期工具描述需要把 cad-mcp-aec.json 的 tools 追加到 部署目录的 cad-mcp-frame.json(插件侧的 private_description 已内置同样的文案)。
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
#define WINVER 0x0600
|
|
|
|
#pragma warning(disable: 4786)
|
|
|
|
//- 'DEBUG workaround' below prevents the MFC or ATL #include-s from pulling
|
|
//- in "Afx.h" that would force the debug CRT through #pragma-s.
|
|
#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
|
|
#define _DEBUG_WAS_DEFINED
|
|
#undef _DEBUG
|
|
#pragma message ("Compiling MFC / STL / ATL header files in release mode.")
|
|
#endif
|
|
|
|
#pragma pack (push, 8)
|
|
#pragma warning(disable: 4786 4996)
|
|
|
|
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
|
|
|
|
#include <afxwin.h> // MFC core and standard components
|
|
#include <afxext.h> // MFC extensions
|
|
|
|
#ifndef _AFX_NO_OLE_SUPPORT
|
|
#include <afxole.h> // MFC OLE classes
|
|
#include <afxodlgs.h> // MFC OLE dialog classes
|
|
#include <afxdisp.h> // MFC Automation classes
|
|
#endif
|
|
|
|
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
|
|
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
|
#include <afxcmn.h> // MFC support for Windows Common Controls
|
|
#endif
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifdef _DEBUG_WAS_DEFINED
|
|
#define _DEBUG
|
|
#undef _DEBUG_WAS_DEFINED
|
|
#endif
|