iT邦幫忙

2025 iThome 鐵人賽

DAY 17
0

對於IFC語法格式有初步的了解之後,今天我們要來看的是如何來編輯修訂它們。

17.1. 主流開源BIM/IFC工具

17.1.1. BlenderBIM

  熟悉CG (Computer Graphics)產業的朋友應該都知道Blender這套免費3D軟體吧?而BlenderBIM就是基於Blender中的一個插件外掛,雖然它不像商業軟體那麼廣泛被採用,但免費真的是很大一個誘因
  由於Blender學習曲線高、不容易上手,且Blender 本身定位在 3D 建模與動畫製作,缺乏原生的 BIM 思維與流程,不過因為BlenderBIM是開源專案,能夠客製化撰寫外掛,甚至與其他 Python 工具鏈結合,可實現高度自動化的處理流程。因此使用時,若加上理解 IFC 概念與資料結構,就能真正發揮它的威力。

17.1.2. IfcOpenShell

  BlenderBIM 背後的關鍵技術之一,就是 IfcOpenShell。因此不論是需要做 IFC 模型的讀取、修改、轉換,甚至自動化批次處理,都可以用它來實現,其常用模組會有以下幾類,更多內容可詳IfcOpenShell 0.8.3 文檔 Python 模組索引

  • ifcopenshell.file:基本開啟、建立與儲存
  • ifcopenshell.guid:產生與解析 GlobalId
  • ifcopenshell.api. :高階 API,可再細分為geometry、material、unit…等
  • IfcConvert:批次轉檔

例如以高階API導入模組的範例:

!pip install ifcopenshell
import ifcopenshell, ifcopenshell.guid as guid

new_id = lambda: guid.new()

m = ifcopenshell.file(schema="IFC4")

# 1) 專案 + 幾何脈絡(3D)
proj = m.create_entity("IfcProject", GlobalId=new_id(), Name="Demo Project")
wcs  = m.create_entity("IfcAxis2Placement3D",
        Location=m.create_entity("IfcCartesianPoint", Coordinates=(0.0,0.0,0.0)),
        Axis=m.create_entity("IfcDirection", DirectionRatios=(0.0,0.0,1.0)),
        RefDirection=m.create_entity("IfcDirection", DirectionRatios=(1.0,0.0,0.0)))
ctx3 = m.create_entity("IfcGeometricRepresentationContext",
        ContextIdentifier="Body", ContextType="Model", CoordinateSpaceDimension=3,
        Precision=1e-5, WorldCoordinateSystem=wcs)

# 2) 空間階層(Site → Building → Storey)
site   = m.create_entity("IfcSite", GlobalId=new_id(), Name="Site")
bldg   = m.create_entity("IfcBuilding", GlobalId=new_id(), Name="Building")
storey = m.create_entity("IfcBuildingStorey", GlobalId=new_id(), Name="Level 1")

m.create_entity("IfcRelAggregates", GlobalId=new_id(), RelatingObject=proj, RelatedObjects=[site])
m.create_entity("IfcRelAggregates", GlobalId=new_id(), RelatingObject=site,  RelatedObjects=[bldg])
m.create_entity("IfcRelAggregates", GlobalId=new_id(), RelatingObject=bldg,  RelatedObjects=[storey])

# (可選)樓層放置:改 z 可抬高樓層
storey_lp = m.create_entity("IfcLocalPlacement",
    RelativePlacement=m.create_entity("IfcAxis2Placement3D",
        Location=m.create_entity("IfcCartesianPoint", Coordinates=(0.0,0.0,0.0)),
        Axis=m.create_entity("IfcDirection", DirectionRatios=(0.0,0.0,1.0)),
        RefDirection=m.create_entity("IfcDirection", DirectionRatios=(1.0,0.0,0.0))))
storey.ObjectPlacement = storey_lp

# 3) 一扇門(方盒示意幾何:W=900, H=2100, T=50)
door = m.create_entity("IfcDoor", GlobalId=new_id(), Name="D1",
                       OverallWidth=900.0, OverallHeight=2100.0)

# 門位置:相對樓層 x=3000mm
door_lp = m.create_entity("IfcLocalPlacement", PlacementRelTo=storey_lp,
    RelativePlacement=m.create_entity("IfcAxis2Placement3D",
        Location=m.create_entity("IfcCartesianPoint", Coordinates=(3000.0,0.0,0.0)),
        Axis=m.create_entity("IfcDirection", DirectionRatios=(0.0,0.0,1.0)),
        RefDirection=m.create_entity("IfcDirection", DirectionRatios=(1.0,0.0,0.0))))
door.ObjectPlacement = door_lp

# 幾何:矩形剖面 + 沿 Z 拉伸
rect = m.create_entity("IfcRectangleProfileDef", ProfileType="AREA",
    Position=m.create_entity("IfcAxis2Placement2D",
        Location=m.create_entity("IfcCartesianPoint", Coordinates=(0.0,0.0)),
        RefDirection=m.create_entity("IfcDirection", DirectionRatios=(1.0,0.0))),
    XDim=900.0,  # 寬
    YDim=50.0)   # 厚
solid = m.create_entity("IfcExtrudedAreaSolid", SweptArea=rect,
    Position=m.create_entity("IfcAxis2Placement3D",
        Location=m.create_entity("IfcCartesianPoint", Coordinates=(0.0,0.0,0.0)),
        Axis=m.create_entity("IfcDirection", DirectionRatios=(0.0,0.0,1.0)),
        RefDirection=m.create_entity("IfcDirection", DirectionRatios=(1.0,0.0,0.0))),
    ExtrudedDirection=m.create_entity("IfcDirection", DirectionRatios=(0.0,0.0,1.0)),
    Depth=2100.0)  # 高
rep = m.create_entity("IfcShapeRepresentation", ContextOfItems=ctx3,
    RepresentationIdentifier="Body", RepresentationType="SweptSolid", Items=[solid])
door.Representation = m.create_entity("IfcProductDefinitionShape", Representations=[rep])

# 4) 把門放進樓層(ContainedInSpatialStructure)
m.create_entity("IfcRelContainedInSpatialStructure", GlobalId=new_id(),
    RelatingStructure=storey, RelatedElements=[door])

# 5) 寫檔
for e in [proj, ctx3, site, bldg, storey, door]:
    m.add(e)
m.write("door_box.ifc")
print("Saved: door_box.ifc")

https://ithelp.ithome.com.tw/upload/images/20250817/20177646VijyEkkAff.png
圖17.1 IfcOpenShell範例圖

17.2. 開源工具未來發展趨勢

  在現行BIM專案的運作上,常常會遇到專案資料被鎖在專有格式中,雖然在該軟體可使用內建工具或外掛完成自動化,但一旦需要跨平台協作、長期資料保存或整合到其他系統時,這種封閉格式往往會成為資料流通與延伸應用的瓶頸。
  隨著IFC 標準與開源工具持續更新迭代與完善,如果你的目標是長期資料可用性、跨平台協作與自動化應用,減少對單一軟體生態的依賴,或許才是更穩健的投資方向。

(轉向 IFC 的懷抱吧——啊嘶~~)/images/emoticon/emoticon48.gif

17.3. 結語

  今天簡單介紹了BlenderBIM和IfcOpenShell,雖然它們可能還無法完全取代成熟的商業套件,但卻給了我們另一條發展的路。下一篇,我們一起來探索AI辨識結果與BIM數據建模的概念吧,明天見!


上一篇
Day16:BIM與IFC標準介紹及數據流架構
下一篇
Day18:AI辨識結果與BIM建模數據流架構
系列文
AI圖像辨識輔助的BIM資料流自動化流程30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言