返回顶部
d

dgn-to-excel" DGN转Excel

Convert DGN files (v7-v8) to Excel databases. Extract elements, levels, and properties from infrastructure CAD files."

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 2.0.0
安全检测
已通过
1,209
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

dgn-to-excel"

DGN 转 Excel 转换

业务案例

问题陈述

DGN 文件在基础设施和土木工程中很常见:
  • - 交通与公路设计
  • 桥梁与隧道项目
  • 公用事业网络
  • 铁路基础设施

从 DGN 文件中提取结构化数据用于分析和报告可能具有挑战性。

解决方案

将 DGN 文件转换为结构化 Excel 数据库,支持 v7 和 v8 格式。

业务价值

  • - 基础设施支持 - 专注于土木工程
  • 旧格式支持 - V7 和 V8 DGN 文件
  • 数据提取 - 图层、单元、文本、几何图形
  • 批量处理 - 处理多个文件
  • 结构化输出 - Excel 格式便于分析

技术实现

CLI 语法

bash DgnExporter.exe <输入_dgn>

支持的版本
版本描述
V7 DGN旧版 MicroStation 格式(V8 之前)
V8 DGN
现代 MicroStation 格式 |

| V8i DGN | MicroStation V8i 格式 |

输出格式
输出描述
.xlsx包含所有元素的 Excel 数据库

示例

bash

基本转换


DgnExporter.exe C:\Projects\Bridge.dgn

批量处理

for /R C:\Infrastructure %f in (*.dgn) do DgnExporter.exe %f

PowerShell 批量处理

Get-ChildItem C:\Projects\*.dgn -Recurse | ForEach-Object { & C:\DDC\DgnExporter.exe $_.FullName }

Python 集成

python
import subprocess
import pandas as pd
from pathlib import Path
from typing import List, Optional, Dict, Any
from dataclasses import dataclass
from enum import Enum

class DGNElementType(Enum):
DGN 元素类型。
CELL_HEADER = 2
LINE = 3
LINE_STRING = 4
SHAPE = 6
TEXT_NODE = 7
CURVE = 11
COMPLEX_CHAIN = 12
COMPLEX_SHAPE = 14
ELLIPSE = 15
ARC = 16
TEXT = 17
SURFACE = 18
SOLID = 19
BSPLINE_CURVE = 21
POINT_STRING = 22
DIMENSION = 33
SHARED_CELL = 35

@dataclass
class DGNElement:
表示一个 DGN 元素。
element_id: int
element_type: int
type_name: str
level: int
color: int
weight: int
style: int

# 几何图形
rangelowx: Optional[float] = None
rangelowy: Optional[float] = None
rangelowz: Optional[float] = None
rangehighx: Optional[float] = None
rangehighy: Optional[float] = None
rangehighz: Optional[float] = None

# 单元/文本特定
cell_name: Optional[str] = None
text_content: Optional[str] = None

@dataclass
class DGNLevel:
表示一个 DGN 图层。
number: int
name: str
is_displayed: bool
is_frozen: bool
element_count: int

class DGNExporter:
使用 DDC DgnExporter CLI 的 DGN 转 Excel 转换器。

def init(self, exporter_path: str = DgnExporter.exe):
self.exporter = Path(exporter_path)
if not self.exporter.exists():
raise FileNotFoundError(f未找到 DgnExporter:{exporter_path})

def convert(self, dgn_file: str) -> Path:
将 DGN 文件转换为 Excel。
dgnpath = Path(dgnfile)
if not dgn_path.exists():
raise FileNotFoundError(f未找到 DGN 文件:{dgn_file})

cmd = [str(self.exporter), str(dgn_path)]
result = subprocess.run(cmd, capture_output=True, text=True)

if result.returncode != 0:
raise RuntimeError(f导出失败:{result.stderr})

return dgnpath.withsuffix(.xlsx)

def batch_convert(self, folder: str,
include_subfolders: bool = True) -> List[Dict[str, Any]]:
转换文件夹中的所有 DGN 文件。
folder_path = Path(folder)
pattern = /.dgn if include_subfolders else .dgn

results = []
for dgnfile in folderpath.glob(pattern):
try:
output = self.convert(str(dgn_file))
results.append({
input: str(dgn_file),
output: str(output),
status: success
})
print(f✓ 已转换:{dgn_file.name})
except Exception as e:
results.append({
input: str(dgn_file),
output: None,
status: failed,
error: str(e)
})
print(f✗ 失败:{dgn_file.name} - {e})

return results

def readelements(self, xlsxfile: str) -> pd.DataFrame:
将转换后的 Excel 读取为 DataFrame。
return pd.readexcel(xlsxfile, sheet_name=Elements)

def getlevels(self, xlsxfile: str) -> pd.DataFrame:
获取图层摘要。
df = self.readelements(xlsxfile)

if Level not in df.columns:
raise ValueError(未找到图层列)

summary = df.groupby(Level).agg({
ElementId: count
}).reset_index()
summary.columns = [Level, Element_Count]
return summary.sort_values(Level)

def getelementtypes(self, xlsx_file: str) -> pd.DataFrame:
获取元素类型统计信息。
df = self.readelements(xlsxfile)

type_col = ElementType if ElementType in df.columns else Type
if type_col not in df.columns:
return pd.DataFrame()

summary = df.groupby(type_col).agg({
ElementId: count
}).reset_index()
summary.columns = [Element_Type, Count]
return summary.sort_values(Count, ascending=False)

def getcells(self, xlsxfile: str) -> pd.DataFrame:
获取单元引用(类似于 DWG 中的块)。
df = self.readelements(xlsxfile)

# 过滤出单元元素
cells = df[df[ElementType].isin([2, 35])] # CELLHEADER, SHAREDCELL

if cells.empty or CellName not in cells.columns:
return pd.DataFrame(columns=[Cell_Name, Count])

summary = cells.groupby(CellName).agg({
ElementId: count
}).reset_index()
summary.columns = [Cell_Name, Count]
return summary.sort_values(Count, ascending=False)

def gettextcontent(self, xlsx_file: str) -> pd.DataFrame:
从 DGN 中提取所有文本。
df = self.readelements(xlsxfile)

# 过滤出文本元素
texttypes = [7, 17] # TEXTNODE, TEXT
texts = df[df[ElementType].isin(text_types)]

if TextContent in texts.columns:
return texts[[ElementId, Level, TextContent]].copy()
return texts[[ElementId, Level]].copy()

def getstatistics(self, xlsxfile: str) -> Dict[str, Any]:
获取全面的 DGN 统计信息。
df = self.readelements(xlsxfile)

stats = {
total_elements: len(df),
levels_used: df[Level].nunique() if Level in df.columns else 0,
element_types: df[ElementType].nunique() if ElementType in df.columns else 0
}

# 计算范围
for coord in [X, Y, Z]:
low_col = fRangeLow{coord}
high_col = fRangeHigh{coord}
if lowcol in df.columns and highcol in df.columns:
stats[fmin{coord.lower()}] = df[lowcol].min()
stats[fmax{coord.lower()}] = df[highcol].max()

return stats

class DGNAnalyzer:
用于基础设施项目的高级 DGN 分析。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 dgn-to-excel-1776345330 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 dgn-to-excel-1776345330 技能

通过命令行安装

skillhub install dgn-to-excel-1776345330

下载

⬇ 下载 dgn-to-excel" v2.0.0(免费)

文件大小: 6.36 KB | 发布时间: 2026-4-17 14:49

v2.0.0 最新 2026-4-17 14:49
dgn-to-excel v2.0.0

- Converts DGN files (V7, V8, V8i) to structured Excel databases.
- Extracts and summarizes elements, levels, cells, and key properties for civil/infrastructure CAD workflows.
- Supports batch processing of multiple DGN files through CLI and Python integration.
- Provides a Python API for programmatic conversion and analysis, including statistics and advanced queries.
- Designed for seamless integration into engineering data pipelines and reporting.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部