Convert IFC files (2x3, 4x1, 4x3) to Excel databases using IfcExporter CLI. Extract BIM data, properties, and geometry without proprietary software."
| 版本 | 架构 | 描述 |
|---|---|---|
| IFC2x3 | MVD | 最常见的交换格式 |
| IFC4 |
| 输出 | 描述 |
|---|---|
| .xlsx | 包含元素和属性的 Excel 数据库 |
| .dae |
| 选项 | 描述 |
|---|---|
| bbox | 包含元素边界框 |
| -no-xlsx |
bash
python
import subprocess
import pandas as pd
from pathlib import Path
from typing import List, Optional, Dict, Any, Set
from dataclasses import dataclass, field
from enum import Enum
import json
class IFCVersion(Enum):
IFC 架构版本。
IFC2X3 = IFC2X3
IFC4 = IFC4
IFC4X1 = IFC4X1
IFC4X3 = IFC4X3
class IFCEntityType(Enum):
常见 IFC 实体类型。
IFCWALL = IfcWall
IFCWALLSTANDARDCASE = IfcWallStandardCase
IFCSLAB = IfcSlab
IFCCOLUMN = IfcColumn
IFCBEAM = IfcBeam
IFCDOOR = IfcDoor
IFCWINDOW = IfcWindow
IFCROOF = IfcRoof
IFCSTAIR = IfcStair
IFCRAILING = IfcRailing
IFCFURNISHINGELEMENT = IfcFurnishingElement
IFCSPACE = IfcSpace
IFCBUILDINGSTOREY = IfcBuildingStorey
IFCBUILDING = IfcBuilding
IFCSITE = IfcSite
@dataclass
class IFCElement:
表示一个 IFC 元素。
global_id: str
ifc_type: str
name: str
description: Optional[str]
object_type: Optional[str]
level: Optional[str]
# 数量
area: Optional[float] = None
volume: Optional[float] = None
length: Optional[float] = None
height: Optional[float] = None
width: Optional[float] = None
# 边界框(如果导出)
bboxminx: Optional[float] = None
bboxminy: Optional[float] = None
bboxminz: Optional[float] = None
bboxmaxx: Optional[float] = None
bboxmaxy: Optional[float] = None
bboxmaxz: Optional[float] = None
# 属性
properties: Dict[str, Any] = field(default_factory=dict)
materials: List[str] = field(default_factory=list)
@dataclass
class IFCProperty:
表示一个 IFC 属性。
pset_name: str
property_name: str
value: Any
value_type: str
@dataclass
class IFCMaterial:
表示一个 IFC 材料。
name: str
category: Optional[str]
thickness: Optional[float]
layer_position: Optional[int]
class IFCExporter:
使用 DDC IfcExporter CLI 的 IFC 转 Excel 转换器。
def init(self, exporter_path: str = IfcExporter.exe):
self.exporter = Path(exporter_path)
if not self.exporter.exists():
raise FileNotFoundError(f未找到 IfcExporter:{exporter_path})
def convert(self, ifc_file: str,
include_bbox: bool = True,
export_xlsx: bool = True,
export_collada: bool = True) -> Path:
将 IFC 文件转换为 Excel。
ifcpath = Path(ifcfile)
if not ifc_path.exists():
raise FileNotFoundError(f未找到 IFC 文件:{ifc_file})
cmd = [str(self.exporter), str(ifc_path)]
if include_bbox:
cmd.append(bbox)
if not export_xlsx:
cmd.append(-no-xlsx)
if not export_collada:
cmd.append(-no-collada)
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
raise RuntimeError(f导出失败:{result.stderr})
return ifcpath.withsuffix(.xlsx)
def batch_convert(self, folder: str,
include_subfolders: bool = True,
include_bbox: bool = True) -> List[Dict[str, Any]]:
转换文件夹中的所有 IFC 文件。
folder_path = Path(folder)
pattern = /.ifc if include_subfolders else .ifc
results = []
for ifcfile in folderpath.glob(pattern):
try:
output = self.convert(str(ifcfile), includebbox)
results.append({
input: str(ifc_file),
output: str(output),
status: success
})
print(f✓ 已转换:{ifc_file.name})
except Exception as e:
results.append({
input: str(ifc_file),
output: None,
status: failed,
error: str(e)
})
print(f✗ 失败:{ifc_file.name} - {e})
return results
def readelements(self, xlsxfile: str) -> pd.DataFrame:
将转换后的 Excel 读取为 DataFrame。
return pd.readexcel(xlsxfile, sheet_name=Elements)
def getelementtypes(self, xlsx_file: str) -> pd.DataFrame:
获取元素类型摘要。
df = self.readelements(xlsxfile)
if IfcType not in df.columns:
raise ValueError(未找到 IfcType 列)
summary = df.groupby(IfcType).agg({
GlobalId: count,
Volume: sum if Volume in df.columns else count,
Area: sum if Area in df.columns else count
}).reset_index()
summary.columns = [IFCType, Count, TotalVolume, Total_Area]
return summary.sort_values(Count, ascending=False)
def getlevels(self, xlsxfile: str) -> pd.DataFrame:
获取建筑楼层摘要。
df = self.readelements(xlsxfile)
level_col = None
for col in [Level, BuildingStorey, IfcBuildingStorey]:
if col in df.columns:
level_col = col
break
if level_col is None:
return pd.DataFrame(columns=[Level, Element_
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 ifc-to-excel-1776345264 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 ifc-to-excel-1776345264 技能
skillhub install ifc-to-excel-1776345264
文件大小: 6.65 KB | 发布时间: 2026-4-17 15:04