python - IfcOpenShell:尝试返回包含 ifcopenshell 对象及其相应形状的字典时出现段错误
问题描述
我试图从 ifc 文件中提取所有 IfcProduct 形状并将它们(及其相应的产品)返回到我程序的另一部分。问题是,当我尝试返回包含具有相应形状的这些对象的字典时,程序会因分段错误而退出。在调试时,我看到数据保存在数据结构中,但在返回后或尝试访问此 dict 中包含的数据时,调试器以段错误退出。
我通过 conda 安装了 ifcopenshell,它在 ubuntu docker vm 中运行。
这是我试图运行的代码:
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
解决方案
通过将 shape_entry 字典中的产品解析为字符串来修复我的代码中的问题。
shape_entry = {"guid": product.GlobalId,
"product": str(product),
"shape": shape}
推荐阅读
- image - 我需要添加一个复选框并添加更多图像(+ 图标),通过它我可以继续在 Flutter 中添加屏幕截图,其中包含进度条
- c# - Visual Studio:打开文档并在修改时显示它
- python - 如何通过从另一个数据框中随机选择来创建数据框?
- python - 如何将 python 路径与递归 glob 模式匹配
- typescript - express res.redirect() 在登录时不起作用
- node.js - npx create-react-app myapp 生成 FETCH_ERROR
- google-cloud-sql - 无法增加 Cloud SQL 存储
- laravel - 如何使用所见即所得的 php 中的数据库中的数据设置阅读更多按钮
- php - PHP fopen不断输入URL失败
- java - VS Code 无法解析我在同一目录中创建的 Java 类型