IfcOpenShell:尝试返回包含IfcOpenShell对象及其相应形状的字典时出现Segfault

2024-10-02 14:25:10 发布

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

我试图从ifc文件中提取所有IfcProduct形状,并将它们(及其相应的产品)返回到我程序的另一部分。问题是,当我试图返回一个包含这些对象及其相应形状的字典时,程序退出时会出现分段错误。在调试过程中,我看到数据保存在数据结构中,但在返回或尝试访问此dict中包含的数据之后,调试器将带SEGFULT退出

我通过conda安装了ifcopenshell,并在ubuntu docker虚拟机上运行

这是我试图运行的代码:

def create_shapes_from_ifcopenshell_object(ifcopenshell_object) -> dict:
"""Creates a shape from the given IfcOpenShell Object and returns a dictionary containing the GlobalId as the key
and the product and shape as dictionary."""
try:
    print("Creating shape-objects from IfcProducts.")
    settings = ifcopenshell.geom.settings()
    products = ifcopenshell_object
    product_shapes_dict = {}
    for product in products:
        if product.is_a("IfcOpeningElement") or product.is_a("IfcSite") or product.is_a("IfcAnnotation"):
            continue
        if product.Representation is not None:
            try:
                shape = ifcopenshell.geom.create_shape(settings, product).geometry
            except Exception as e:
                print(str(e) + ". Product:" + str(product))
                continue
            shape_entry = {"guid": product.GlobalId,
                           "product": product,
                           "shape": shape}
            product_shapes_dict[shape_entry["guid"]] = shape_entry
except RuntimeError as re:
    print("Runtime error" + str(re))
    return {"ERROR": str(e)}
except Exception as e:
    print("ERROR during shape creation.")
    return {"ERROR": str(e)}
# pprint(product_shapes_dict) <-- THIS SHOWS THE CORRECT DICT
return product_shapes_dict # <-- Segfault directly after this

Tags: andthefromsettingsobjectisasproduct