You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IFCOPENSHELL提取IFC外墙失败:Blender BIM运行代码无输出

解决IFCopenshell提取外墙返回空集合的问题

问题根源

你的代码存在两个核心问题:

  • 选择器语法格式错误,且属性集名称大小写不匹配(IFC标准中属性集为Pset_WallCommon,而非你写的Pset_Wallcommon)
  • 未接收函数返回值,导致无法看到实际结果

修正后的代码

import ifcopenshell
import ifcopenshell.util.selector

# 打开原IFC模型
model = ifcopenshell.open("C:/Users/x/Downloads/BIM4EEB-TUD-2x3.ifc")

# 修正选择器语法:使用标准属性集名称和正确格式
external_walls = ifcopenshell.util.selector.filter_elements(model, "IfcWall[Pset_WallCommon.IsExternal=True]")

# 输出结果数量,确认是否获取到外墙
print(f"找到 {len(external_walls)} 个外墙")

# 将提取的外墙写入新IFC文件
if external_walls:
    # 创建新的IFC模型
    new_model = ifcopenshell.file()
    # 复制所有外墙元素到新模型
    for wall in external_walls:
        new_model.add(wall)
    # 保存新模型
    new_model.write("C:/Users/x/Downloads/External_Walls.ifc")
    print("新IFC文件已保存")
else:
    print("未找到符合条件的外墙")

备选方案(若选择器仍失效)

如果上述代码还是返回空集合,可能是原IFC文件中属性集的存储方式特殊,可改用遍历检查的方式:

import ifcopenshell
from ifcopenshell.util.element import get_pset

model = ifcopenshell.open("C:/Users/x/Downloads/BIM4EEB-TUD-2x3.ifc")
external_walls = []

for wall in model.by_type("IfcWall"):
    # 获取墙体的通用属性集
    wall_pset = get_pset(wall, "Pset_WallCommon")
    if wall_pset and wall_pset.get("IsExternal") == True:
        external_walls.append(wall)

# 后续写入新文件的步骤和上面一致

内容的提问来源于stack exchange,提问作者H. Ach

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 00:59:59