如何使用python/ifcopenshell,f.ex IfcBuildingElementProxy将对象IfcClassification更改为IfcWindow?

2024-07-02 12:20:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含许多元素的模型,它被分类为ifcbuildingelementproxy(或者未分类为ifc导出软件aka 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$kw1dyuzy2klwwkk',#41,'M\u Muntin Pattern\u 2x2:M\u Muntin Pattern\u 2x2:346152',$,'M\u Muntin Pattern\u 2x2',,,'346152',$)

将显示

13505=IfcWindow('3OAbz$kw1dyuzy2klwwkk',#41,'MŧMuntin Patternŧu2x2:MŧMuntin Patternŧu2x2:346152',$,'MŧMuntin Patternŧu2x2',$,'MŧMuntin Patternŧu2x2',$)


Tags: in元素searchbyistype分类word
2条回答

您不能简单地更改类型。不可能给函数赋值,is_a是一个函数而不是一个属性(通过设计,因为类型是不可修改的)。你知道吗

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

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

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

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

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

注意,它直接在初始文件中进行修改。你知道吗

(注:在Cygwin上测试)

相关问题 更多 >