Files
zwt13703 9feeb14910 feat: 拆分 DXF 解析为模块化结构,新增图层分析和实体分析模块
- 新增 layer_analysis.py:图层实体统计 + 角色推断(22条启发式规则)
- 新增 entity_analysis.py:实体类型统计、INSERT 块聚合、文本提取
- 重构 main.py:调度分析模块,输出 {文件名}_cad_analysis.json
- 新增 README.md 使用说明
- 输出文件名使用模型名作为前缀,避免多次测试覆盖
2026-07-08 14:31:27 +08:00

84 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# DXF 解析工具
解析 DXF 格式的 CAD 图纸文件,输出结构化的图层分析、实体统计、块引用和文本信息。
## 目录结构
```
experiments/dxf-parser/
├── main.py # 入口脚本
├── layer_analysis.py # 图层分析模块
├── entity_analysis.py # 实体分析模块
├── requirements.txt # 依赖
├── output/ # 输出目录
│ └── {文件名}_cad_analysis.json
└── README.md
```
## 安装依赖
```bash
cd experiments/dxf-parser
pip install -r requirements.txt
```
## 使用方式
1. 将要解析的 DXF 文件放入 `samples/` 目录
2. 修改 `main.py` 中的 `DXF_FILE` 变量指向目标文件
3. 运行:
```bash
python main.py
```
## 输出说明
终端会打印解析摘要(图层、实体类型统计、块引用、文本内容),同时在 `output/{文件名}_cad_analysis.json` 中生成结构化 JSON
```json
{
"file_info": {
"filename": "洗浴中心C-48.dxf",
"dxf_version": "AC1032",
"encoding": "gbk",
"units": null,
"extents": { "min": [...], "max": [...] },
"total_entities": 719
},
"layers": [
{
"name": "DOOR",
"entity_count": 52,
"entity_types": ["INSERT", "LINE"],
"suggested_role": "门窗"
}
],
"entities": {
"LINE": 321,
"TEXT": 71
},
"blocks": [
{
"block_name": "A$C6B90F135",
"count": 8,
"inserts": [...]
}
],
"texts": [
{
"handle": "2A",
"layer": "TEXT",
"type": "TEXT",
"content": "办公室",
"insert": [150, 300]
}
]
}
```
## 模块说明
- **layer_analysis.py**:遍历所有图层,统计每层实体数量和类型,基于常见命名规则推断图层角色(仅作建议)
- **entity_analysis.py**:统计模型空间中各实体类型数量,对 INSERT 实体按块名聚合,提取所有 TEXT/MTEXT 文本内容