0

我有一个包含许多元素的模型,这些元素被归类为 ifcbuildingelementproxy(或未分类,因为这是 ifc 导出软件又名 ifcObject 的标准)。我有一个代码可以找到我想要更改其分类的所有元素,但我似乎找不到更改它的方法。我想要做的是让我的脚本将所有名称以“whatever”开头的元素重新分类为 IfcWindow 而不是 IfcBuildingElementProxy。

def re_classify():
    ifc_loc='thefile.ifc'
    ifcfile = ifcopenshell.open(ifc_loc)
    create_guid = lambda: ifcopenshell.guid.compress(uuid.uuid1().hex)
    owner_history = ifcfile.by_type("IfcOwnerHistory")[0]
    element = ifcfile.by_type("IfcElement")
    sets = ifcfile.by_type("IfcPropertySet")
    search_word_in_name='M_Muntin'
    for e in element:
        if e.is_a('IfcBuildingElementProxy'):
            if e.Name.startswith(search_word_in_name,0,len(search_word_in_name)):
                e.is_a()==e.is_a('IfcWindow')   #<--- THIS DOES NOTHING
                print (e)
                print(e.Name,' - ', e.is_a())

re_classify()

我希望 f.ex

13505=IfcBuildingElementProxy('3OAbz$kW1DyuZY2KLwUwkk',#41,'M_Muntin Pattern_2x2:M_Muntin Pattern_2x2:346152',$,'M_Muntin Pattern_2x2',#13504,#13499,'346152',$)

将会呈现

13505=IfcWindow('3OAbz$kW1DyuZY2KLwUwkk',#41,'M_Muntin Pattern_2x2:M_Muntin Pattern_2x2:346152',$,'M_Muntin Pattern_2x2',#13504,#13499,'346152',$)

4

2 回答 2

1

在 Unix/Linux shell 上,您可以使用单行(不使用 Python 或 IfcOpenShell)进行替换,如下所示:

sed -i '/IFCBUILDINGELEMENTPROXY(.*,.*,.M_Muntin/{s/IFCBUILDINGELEMENTPROXY/IFCWINDOW/}' thefile.ifc

请注意,它直接在初始文件中进行修改。

(注意:在 Cygwin 上测试)

于 2019-11-25T15:58:16.857 回答
0

您不能简单地更改类型。不可能给函数赋值,它是is_a函数而不是属性(设计上是因为类型不可修改)。

此外IfcBuildingElementProxyIfcWindow仅共享其属性的子集。那就是IfcBuildingElementProxy有一个IfcWindow没有的,反之亦然。幸运的是, 的附加属性IfcWindow都是可选的。因此,您可以创建一个新的窗口实体,从代理复制公共属性,不设置其他属性并删除代理。

commonAttrs = list(e.get_Info().values())[2:-1]
window = ifcfile.createIfcWindow(*commonAttrs)
ifcfile.remove(e)

您仍然需要查找引用代理的其他实体并将引用替换为对窗口的引用以获得有效的 ifc 文件。

于 2019-11-27T20:52:01.720 回答