【发布时间】:2020-11-26 09:42:44
【问题描述】:
我正在尝试使用 IfcOpenShell 对 IFC 模型进行分类。
在第一步中,我从 IFC 模型元素列表中提取属性 GlobalId 和 ObjectType。然后我想使用ObjectType属性对信息进行排序,以接收来自模型的以下信息:
Basiswand:Bestand 08.0:161894
{'GlobalId': '3vpWoB_K1EZ8RCaYmNGs6M', 'Element': 'Basiswand:Bestand 08.0:161894'}
{'GlobalId': '3vpWoB_K1EZ8RCaYmNGsB2', 'Element': 'Basiswand:Bestand 08.0:161894'}
Fenster 1-flg - Variabel
{'GlobalId': '3vpWoB_K1EZ8RCaYmNGssv', 'Element': 'Fenster 1-flg - Variabel'}
{'GlobalId': '3vpWoB_K1EZ8RCaYmNGsqI', 'Element': 'Fenster 1-flg - Variabel'}
ObjectType 相同,GlobalId 不同的元素应合并为一组,进行分类。
rows =[]
buildingelement = model.by_type('IfcBuildingElement')
for buildingelement in model.by_type('IfcBuildingElement'):
rows.append(str(buildingelement.GlobalId) + ': ' + str(buildingelement.ObjectType))
print(rows)
from operator import itemgetter
from itertools import groupby
# Sort by the desired field first
rows.sort(key=itemgetter('IfcBuildingElement'))
# Iterate in groups
for date, items in groupby(rows, key=itemgetter('IfcBuildingElement')):
print(date)
for i in items:
print(' ', i)
使用上面的代码,我收到错误消息Exception has occurred: TypeError string indices must be integers。
【问题讨论】: