@bill_nee/dwg-reader 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +80 -5
  2. package/lib/index.js +32 -8
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # @bill_nee/dwg-reader
2
2
 
3
- DSH (DeepSeek Harness) 插件:可直接读取 AutoCAD DWG 格式图纸,无需安装 AutoCAD。
3
+ DSH(DeepSeek Harness)插件:可直接读取 AutoCAD DWG 格式图纸,无需安装 AutoCAD。
4
4
 
5
5
  基于 [libredwg-web](https://github.com/mlightcad/libredwg-web) 0.8.2 WASM 编译,在浏览器/Node 环境中解析 DWG 文件,返回图层、实体、版本、编码、图幅等信息,并可导出 SVG 预览。
6
6
 
7
7
  ## 安装
8
8
 
9
+ 在 DSH 工作台或终端执行:
10
+
9
11
  ```powershell
10
12
  dsh plugin --profile desktop add @bill_nee/dwg-reader@1.1.0
11
13
  ```
@@ -14,11 +16,84 @@ dsh plugin --profile desktop add @bill_nee/dwg-reader@1.1.0
14
16
 
15
17
  ## 主要能力
16
18
 
17
- - 读取 DWG(AutoCAD R14~R2018 等常见版本)
18
- - 返回图层列表、实体类型与数量、图纸版本(ACADVER)、代码页、图幅
19
- - 导出 SVG 预览到指定路径
20
- - 对无效/损坏文件给出明确错误
19
+ | 能力 | 说明 |
20
+ |------|------|
21
+ | 读取 DWG | 支持 AutoCAD R14~R2018 等常见版本(AC1015~AC1032) |
22
+ | 图层信息 | 返回所有图层名称、颜色、冻结/关闭/锁定状态 |
23
+ | 实体统计 | 返回实体总数及按类型(LINE/TEXT/INSERT/HATCH/DIMENSION 等)分类统计 |
24
+ | 图纸版本 | 返回 ACADVER、版本号、版本描述(如 r2018/AC1032/AutoCAD Release 2018) |
25
+ | 代码页 | 返回 DWG 代码页(如 CP_ANSI_936) |
26
+ | 图幅信息 | 返回 EXTMIN/EXTMAX 边界框 |
27
+ | 导出 SVG | 可将 DWG 内容导出为 SVG 预览文件到指定路径 |
28
+ | 错误处理 | 对无效/损坏/非 DWG 文件给出明确错误提示 |
29
+
30
+ ## 使用示例
31
+
32
+ 在 DSH 工作台调用 `read_dwg` 工具:
33
+
34
+ ```json
35
+ {
36
+ "file_path": "E:\\2026 工程资料\\16 天喔蜜饯工厂\\03 CAD DESIGN\\02 HVAC DESIGN PLAN.dwg",
37
+ "entities": true,
38
+ "entity_limit": 50,
39
+ "export_svg": true,
40
+ "svg_output_path": "F:\\HAYNESS 工作区1\\hvac-plan.svg"
41
+ }
42
+ ```
43
+
44
+ 返回示例:
45
+
46
+ ```json
47
+ {
48
+ "file_path": "E:\\...\\02 HVAC DESIGN PLAN.dwg",
49
+ "file_size": 123456,
50
+ "version": { "type": "r2018", "hdr": "AC1032", "description": "AutoCAD Release 2018", "version": 33 },
51
+ "codepage": 39,
52
+ "codepageName": "CP_ANSI_936",
53
+ "layer_count": 126,
54
+ "entity_count": 1514,
55
+ "unknown_entity_count": 0,
56
+ "extents": { "min": { "x": 0, "y": 0, "z": 0 }, "max": { "x": 266000, "y": 286000, "z": 0 } },
57
+ "layers": [ { "name": "HEPA BOX", "colorIndex": 5, ... }, ... ],
58
+ "entities": [
59
+ { "type": "INSERT", "handle": "...", "layer": "HEPA BOX", "blockName": "...", ... },
60
+ ...
61
+ ],
62
+ "svg_path": "F:\\HAYNESS 工作区1\\hvac-plan.svg"
63
+ }
64
+ ```
65
+
66
+ ## 测试实例
67
+
68
+ 已对真实工程图纸进行验证:
69
+
70
+ - **天喔蜜饯工厂暖通图纸**(r2018/AC1032):1514 个实体,126 个图层,其中高效送风口(HEPA BOX 图层)108 个,方形散流器 18 个,射流空调 5 个。
71
+ - **植本清源空调设备图**(r2007/AC1021):1762 个实体,14 个图层。
72
+ - **无效/损坏文件**:返回明确错误,不崩溃。
73
+
74
+ ## 文件结构
75
+
76
+ ```
77
+ dwg-reader-plugin/
78
+ ├── lib/index.js # 插件入口,注册 read_dwg 工具
79
+ ├── cordis.patch.yml # DSH bundle 插件清单
80
+ ├── package.json # npm 包清单
81
+ ├── LICENSE # GPL-3.0-only
82
+ ├── README.md # 本文件
83
+ ├── icon.svg # 插件图标
84
+ ├── locale/en.json # 英文元数据
85
+ ├── locale/zh.json # 中文元数据
86
+ └── vendor/libredwg-web/ # libredwg-web 0.8.2 WASM 库(已 vendored)
87
+ ├── lib/ # JS 封装层
88
+ └── wasm/ # libredwg-web.wasm(WebAssembly 解析核心)
89
+ ```
21
90
 
22
91
  ## 许可
23
92
 
24
93
  GPL-3.0-only。依赖 libredwg-web 同样为 GPL,公开分发请保留 LICENSE 并提供对应源码。
94
+
95
+ ## 安装路径
96
+
97
+ - npm 公开包:`@bill_nee/dwg-reader@1.1.0`
98
+ - 安装命令:`dsh plugin --profile desktop add @bill_nee/dwg-reader@1.1.0`
99
+ - GitHub 源码:https://github.com/NIDEXIANG/dwg-reader-plugin-20261029
package/lib/index.js CHANGED
@@ -272,14 +272,38 @@ function buildReadDwgTool(ctx) {
272
272
 
273
273
  const limit = Math.min(Math.max(1, args.entity_limit || 200), MAX_ENTITY_DETAIL);
274
274
  const detailEntities = args.entities ? database.entities.slice(0, limit) : [];
275
- const entities = detailEntities.map((entity) => ({
276
- type: entity.type || "UNKNOWN",
277
- handle: entity.handle != null ? entity.handle : null,
278
- layer: entity.layer != null ? entity.layer : null,
279
- colorIndex: typeof entity.colorIndex === "number" ? entity.colorIndex : null,
280
- lineType: entity.lineType != null ? entity.lineType : null,
281
- isInPaperSpace: !!entity.isInPaperSpace,
282
- }));
275
+ const entities = detailEntities.map((entity) => {
276
+ const base = {
277
+ type: entity.type || "UNKNOWN",
278
+ handle: entity.handle != null ? entity.handle : null,
279
+ layer: entity.layer != null ? entity.layer : null,
280
+ colorIndex: typeof entity.colorIndex === "number" ? entity.colorIndex : null,
281
+ lineType: entity.lineType != null ? entity.lineType : null,
282
+ isInPaperSpace: !!entity.isInPaperSpace,
283
+ };
284
+ if (entity.type === "INSERT") {
285
+ base.blockName = entity.name != null ? String(entity.name) : null;
286
+ base.insertionPoint = entity.insertionPoint
287
+ ? { x: entity.insertionPoint.x, y: entity.insertionPoint.y, z: entity.insertionPoint.z }
288
+ : null;
289
+ base.rotation = typeof entity.rotation === "number" ? entity.rotation : null;
290
+ base.scale = entity.scale
291
+ ? { x: entity.scale.x, y: entity.scale.y, z: entity.scale.z }
292
+ : null;
293
+ base.attribs = Array.isArray(entity.attribs)
294
+ ? entity.attribs.map((a) => ({
295
+ tag: a.tag != null ? String(a.tag) : null,
296
+ text: a.text != null ? String(a.text) : null,
297
+ prompt: a.prompt != null ? String(a.prompt) : null,
298
+ value: a.value != null ? String(a.value) : null,
299
+ insertionPoint: a.insertionPoint
300
+ ? { x: a.insertionPoint.x, y: a.insertionPoint.y, z: a.insertionPoint.z }
301
+ : null,
302
+ }))
303
+ : [];
304
+ }
305
+ return base;
306
+ });
283
307
 
284
308
  let svgPath = null;
285
309
  if (args.export_svg) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bill_nee/dwg-reader",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "直接读取 AutoCAD DWG 图纸的 DSH 插件(基于 libredwg-web 0.8.2 WASM,GPL-3.0)。",
5
5
  "license": "GPL-3.0-only",
6
6
  "author": "MEB 工程造价项目助手 <meb@example.com>",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/dwg-reader-plugin/dwg-reader"
9
+ "url": "https://github.com/NIDEXIANG/dwg-reader-plugin-20261029.git"
10
10
  },
11
11
  "keywords": ["dwg", "dwg-reader", "autocad", "cad", "dsh-plugin", "libredwg", "wasm"],
12
12
  "type": "module",