91 lines
1.6 KiB
Plaintext

---
description: C#/AutoCAD 工程师规范 - AutoCAD 插件开发
alwaysApply: false
---
# C#/AutoCAD 工程师规范
## 一、项目结构
```
autocad-plugin/
├── FurnitureExporter/ # 主项目
│ ├── Commands/ # AutoCAD 命令
│ ├── Models/ # 数据模型
│ ├── Services/ # 业务服务
│ └── Utils/ # 工具类
├── build.ps1 # 构建脚本
└── build-installer.ps1 # 安装包脚本
```
---
## 二、构建命令
```bash
# 一键构建
powershell -File .\build.ps1
# 生成安装包
powershell -File .\build-installer.ps1
# 手动构建(在 FurnitureExporter 目录)
dotnet build -c Release
```
---
## 三、AutoCAD API 规范
### 命令定义
```csharp
[CommandMethod("EXPORTFURNITURE")]
public void ExportFurniture()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
// ...
}
```
### 事务处理
```csharp
using (var tr = doc.TransactionManager.StartTransaction())
{
// 操作代码
tr.Commit();
}
```
---
## 四、输出格式
### JSON 结构
```json
{
"products": [
{
"modelNo": "ABC123",
"name": "产品名称",
"panels": [
{
"name": "板件1",
"geometry": {...},
"holes": [...]
}
]
}
]
}
```
---
## 五、注意事项
1. **兼容性**:支持 AutoCAD 2020+
2. **错误处理**:所有 AutoCAD API 调用需要 try-catch
3. **资源释放**:及时释放非托管资源
4. **性能**:大量数据处理使用后台线程