Files
Design-Express-Res/README.md
T

114 lines
5.8 KiB
Markdown
Raw Normal View History

2026-08-22 17:20:02 +08:00
# Design Express Res — CAD 设计标注检查与设计数据查询工具
基于 **Core + Link 架构**(类似 COMSOL LiveLink):独立核心库与 CAD 完全解耦,Inventor / SolidWorks 各自通过 Link 适配层调用 Core 功能。
## 架构
```
┌────────────────────────────────────────────┐
│ DesignExpress.Core.dll (独立核心, 不依赖CAD) │
│ - KB 知识库 (GB/T 275/1800/1801/894/1095) │
│ - CheckEngine 检查引擎 (P/A/D 三阶段) │
│ - DesignQuery 设计数据查询 (键槽/卡簧槽已实装)│
│ - UI: MainForm/QueryForm/FitForm │
│ - Report 报告 (Excel/CSV) │
│ - ICadHost 抽象接口 + DocSnapshot 快照 │
│ - ToolIcons 共享图标(仓鼠品牌+功能符号) │
└────────────────────────────────────────────┘
▲ ▲
InventorLink SolidWorksLink
(已交付) (已交付)
```
- **ICadHost 接口**:`GetActiveDocument / GetDocType / Capture / PickCylinderDiameterMM / SetStatusText`
- **DocSnapshot 快照**:Link 层把 CAD 文档状态拍成纯数据,Core 只处理快照
- 新增 CAD 支持 = 实现一个 ICadHost + 该 CAD 的选项卡壳
## 功能
| 系统 | 内容 |
|------|------|
| 设计检查 | 零件(标注/公差配合GB/T 275/形位/粗糙度/螺纹/物料接触GMP/表面处理/强度指引)、装配(GMP材料/密封/清洁/静态干涉/外购件/电气西门子/动力)、工程图(图框/视图/尺寸公差/22项spec关键词检查) |
| 设计数据查询 | 键槽(GB/T 1095)、卡簧槽(GB/T 894.1)已实装; O型密封圈(GB/T 3452.1)、轴承挡圈规划中 |
## 部署
### Inventor
1. 复制 `AddIn/deploy` 文件夹到目标机器
2. 右键 `install.ps1` → **使用 PowerShell 运行**(无需管理员)
3. 重启 Inventor,功能区出现 **[Design Express Res]** 选项卡
### SolidWorks
1. 复制 `AddIn/deploy` 文件夹
2. 运行 `install_solidworks.ps1`(用户级注册)
3. **首次需管理员执行两条 reg add**(脚本末尾有提示):
- `HKLM\SOFTWARE\SolidWorks\AddIns\{4A7E023E-...}` 键(default=1, Title)
4. 启动 SolidWorks → 工具→插件 勾选 Design Express Res
5. 打开零件 → 出现选项卡 → **正常退出并重启一次**(持久化选项卡定义)
## 文件清单
| 路径 | 说明 |
|------|------|
| `AddIn/deploy/DesignExpress.Core.dll` | 独立核心(成品) |
| `AddIn/deploy/DesignExpress.InventorLink.dll` | Inventor 适配层(成品) |
| `AddIn/deploy/DesignExpress.SolidWorksLink.dll` | SolidWorks 适配层(成品) |
| `AddIn/deploy/install.ps1` | Inventor 一键部署脚本 |
| `AddIn/deploy/install_solidworks.ps1` | SolidWorks 部署脚本 |
| `AddIn/src/Core/*.cs` | 核心源码(ICadHost/Snapshots/KB/CheckEngine/DesignQuery/UI/ToolIcons) |
| `AddIn/src/InventorLink/*.cs` | Inventor 适配源码 |
| `AddIn/src/SolidWorksLink/*.cs` | SolidWorks 适配源码 |
## 关键技术点
### Inventor
- **按钮点击**:`ButtonDefinition.OnExecute` 事件(不依赖 ExecuteCommand 路由)
- **加载规则**:`AddInLoadRules` 二进制文件控制加载,install.ps1 自动修复(DWORD=0 允许加载)
### SolidWorks
- **延迟创建**:命令组/选项卡在**文档激活事件**(`ActiveDocChangeNotify`)中创建——SW 启动早期命令系统未就绪,ConnectToSW 时创建会静默失败
- **EnableMethod 回调**:命令必须提供启用方法(返回 1),否则 SW 禁用命令导致按钮不可见
- **tab.Active = true**:选项卡可见性 + 激活必须直接设置,否则不显示在选项卡栏
- **持久化**:SW 正常退出时把选项卡定义写入注册表,重启后读取显示
- **GetDocType 注意**:不能 `dynamic.GetType()`(解析成 Object.GetType),必须编译时调用
### 通用
- **窗口**:1/4 屏幕面积,TableLayoutPanel 百分比布局,无固定尺寸不遮罩
- **报告**:Excel COM 动态调用,未装 Excel 回退 CSV
- **图标**:ToolIcons 共享生成(功能符号集中式),SolidWorks 用 9 格 BMP 图标条;Inventor 因 AddButtonDefinition 对 IPictureDisp 兼容性问题暂用文字按钮(可后续手动补图标)
## 建议的 iProperties 自定义属性
| 属性名 | 取值示例 | 用途 |
|--------|----------|------|
| 物料接触 | 直接接触 / 间接接触 / 非接触 | 触发 GMP 专项检查 |
| 表面处理 | 镀镍+磨削 / 抛光 / 发黑 | 表面处理检查 |
| 材料 | 316L / 304 / PTFE | GMP 材料判定 |
## 编译
```powershell
# Core (无 CAD 依赖)
csc /target:library /platform:x64 /codepage:65001 /out:DesignExpress.Core.dll ^
/r:System.Windows.Forms.dll /r:System.Drawing.dll /r:Microsoft.CSharp.dll /r:System.Core.dll ^
src\Core\*.cs
# Inventor Link
csc /target:library /platform:x64 /codepage:65001 /out:DesignExpress.InventorLink.dll ^
/r:DesignExpress.Core.dll /r:"<Inventor>\Bin\Public Assemblies\Autodesk.Inventor.Interop.dll" ^
/r:System.Windows.Forms.dll /r:System.Drawing.dll /r:Microsoft.CSharp.dll /r:System.Core.dll ^
src\InventorLink\*.cs
# SolidWorks Link
csc /target:library /platform:x64 /codepage:65001 /out:DesignExpress.SolidWorksLink.dll ^
/r:DesignExpress.Core.dll /r:"<SW>\SolidWorks.Interop.sldworks.dll" ^
/r:"<SW>\SolidWorks.Interop.swpublished.dll" /r:"<SW>\SolidWorks.Interop.swconst.dll" ^
/r:System.Windows.Forms.dll /r:System.Drawing.dll /r:Microsoft.CSharp.dll /r:System.Core.dll ^
src\SolidWorksLink\*.cs
```
## 版本历史
- **1.3.0** (2026-08-21): SolidWorks Link 交付; 功能图标(集中式功能符号); 生产版代码清理
- **1.3.1** (2026-08-22): 清理调试代码与临时文件; Inventor 图标方案(IPictureDisp)因 API 兼容性暂缓, 保留文字按钮