计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
elements【效率与协作】Use when generating building information models (BIM) programmatically in C#/.NET — wall, beam, column, floor creation, geometry kernel (BREP/CSG), glTF/IFC/JSON serialization, MEP systems, spatial grids. Hypar Elements: the smallest useful BIM — a cross-platform C# library for creating building elements without Revit/Rhino dependencies.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: elements description: "Use when generating building information models (BIM) programmatically in C#/.NET — wall, beam, column, floor creation, geometry kernel (BREP/CSG), glTF/IFC/JSON serialization, MEP systems, spatial grids. Hypar Elements: the smallest useful BIM — a cross-platform C# library for creating building elements without Revit/Rhino dependencies." tags:
项目地址: https://github.com/hypar-io/Elements
官方文档: https://hypar.io/Elements/
NuGet: https://www.nuget.org/packages/Hypar.Elements
许可证: MIT | 最新版本:
2.3.0(NuGet 最高非预发布版;2.4.0 系列尚为 alpha 预发布)
Elements 是 Hypar 公司开源的 建筑信息模型(BIM)编程生成库,专为 AEC(建筑、结构、机电、施工)领域设计。它以纯 C# 代码创建建筑模型——墙、梁、柱、楼板、空间、机电管道等——无需启动任何商业 BIM 软件。
| 特性 | 说明 |
|---|---|
| 跨平台 | netstandard2.0,支持 Linux/macOS/Windows 微服务 |
| 零商业依赖 | 不依赖 Revit、Rhino 或任何商业几何内核 |
| 混合几何内核 | 简洁的 BREP/CSG 混合内核,擅长"平面带孔"类建模 |
| 多格式序列化 | JSON / glTF / GLB / IFC / DXF / SVG |
| Schema 驱动 | JSON Schema 定义自定义元素类型 + 代码生成 |
| 建筑元素 | Wall / Beam / Column / Floor / Panel / Space / Topography |
| MEP 系统 | Fitting 管件体系(弯头/三通/变径)、流路分析 |
| 空间数据结构 | Grid1d/Grid2d 轴网、HalfEdgeGraph2d、CellComplex、AdaptiveGrid |
# NuGet(推荐)
dotnet add package Hypar.Elements
# 可选包
dotnet add package Hypar.Elements.Serialization.IFC # IFC 导入导出
dotnet add package Hypar.Elements.Serialization.DXF # DXF 导入导出
dotnet add package Hypar.Elements.Components # 组件化生成
dotnet add package Hypar.Elements.CodeGeneration # JSON Schema → C# 代码生成
using Elements;
using Elements.Geometry;
using Elements.Serialization.glTF;
// 创建模型
var model = new Model();
// 创建墙
var wall = new Wall(
line: new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)),
height: 3.0,
thickness: 0.2
);
model.AddElement(wall);
// 创建柱
var column = new Column(
location: new Vector3(2.5, 0, 0),
height: 3.0,
profile: Profiles.WideFlangeProfile(width: 0.2, depth: 0.3)
);
model.AddElement(column);
// 导出 glTF
model.ToGlTF("output.glb");
using Elements.Geometry;
// 向量运算
var a = new Vector3(1, 0, 0);
var b = new Vector3(0, 1, 0);
var cross = a.Cross(b); // 叉积
var dot = a.Dot(b); // 点积
var dist = a.DistanceTo(b); // 距离
// 多边形
var polygon = Polygon.Rectangle(4, 3);
var hole = Polygon.Circle(0.5, 8);
var profile = new Profile(polygon, new[] { hole }); // 带洞轮廓
// 变换
var transform = new Transform(new Vector3(5, 0, 0));
var transformedPolygon = polygon.TransformedPolygon(transform);
// 拉伸
var extrude = new Extrude(profile, 3.0, Vector3.ZAxis);
// 扫掠
var sweep = new Sweep(profile, path, angle);
// CSG 布尔运算
var a = new Cube(2, 2, 2);
var b = new Sphere(1.5);
var result = a.Union(b); // 并集
var diff = a.Subtract(b); // 差集
var intersect = a.Intersect(b); // 交集
// JSON
var json = model.ToJson();
var model2 = Model.FromJson(json);
// glTF/GLB
model.ToGlTF("model.glb");
var model3 = Model.FromGlTF("model.glb");
// IFC(需 Hypar.Elements.Serialization.IFC)
model.ToIFC("model.ifc");
var model4 = Model.FromIFC("model.ifc");
using Elements;
using Elements.Geometry;
var model = new Model();
// 地板
var floor = Floor.Create(
profile: Polygon.Rectangle(6, 4),
thickness: 0.3
);
model.AddElement(floor);
// 四面墙
var roomProfile = Polygon.Rectangle(6, 4);
foreach (var segment in roomProfile.Segments())
{
var wall = new Wall(segment, height: 3.0, thickness: 0.15);
model.AddElement(wall);
}
// 柱
for (int x = -2; x <= 2; x += 4)
{
for (int y = -1; y <= 1; y += 2)
{
var col = new Column(
location: new Vector3(x, y, 0),
height: 3.0,
profile: Profiles.WideFlangeProfile(0.15, 0.25)
);
model.AddElement(col);
}
}
// 导出
model.ToGlTF("room.glb");
Vector3.Epsilon = 1e-05 进行浮点比较,使用 IsAlmostEqualTo() 等辅助方法| 问题 | 解决方案 |
|---|---|
| 如何在 Linux 微服务中运行? | Elements 是 netstandard2.0,完全支持 Linux Docker 部署 |
| 如何导出到 Revit? | 通过 IFC 格式中转:Elements → IFC → Revit |
| 几何操作在不同平台结果不一致? | 使用 IsAlmostEqualTo() 等精度辅助方法,避免直接 == 比较 |
| 如何创建自定义建筑元素? | 继承 Element 类,用 JSON Schema 定义属性,用 CodeGeneration 生成代码 |
new Model() → 添加建筑元素(Wall/Column/Floor/Beam)Polygon.Rectangle()、Vector3、Line 构建几何轮廓Extrude(拉伸)、Sweep(扫掠)、CSG 布尔运算(Union/Subtract/Intersect)model.ToGlTF()(推荐 glTF/GLB)、model.ToJson()、model.ToIFC()(需额外包)Element,用 JSON Schema 定义属性,通过 CodeGeneration 生成代码Vector3.Epsilon 和 IsAlmostEqualTo(),不要直接用 ==Hypar.Elements.Serialization.IFC 包