简体   繁体   English

使用 C# 创建 IFC 文件

[英]Create IFC file using C#

Does anyone know if there is already a widespread way of creating IFC files, or at least IFC objects, using C#?有谁知道是否已经有一种使用 C# 创建 IFC 文件或至少 IFC 对象的广泛方法? I am trying to create objects based on class instances that result from a calculation which is coded in C#.我正在尝试基于 class 实例创建对象,这些实例是在 C# 中编码的计算结果。 The use of APIs of authoring software like Revit is not an option in this case.在这种情况下,不能选择使用 Revit 等创作软件的 API。

I know only this resource, but it doesn't seem to contain a way of creating objects, only geometries: https://docs.xbim.net/我只知道这个资源,但它似乎不包含创建对象的方法,只有几何: https://docs.xbim.net/

Would be grateful for any hints or direction pointers.将不胜感激任何提示或方向指针。 Infos about doing the same in other programming languages are also welcome也欢迎有关在其他编程语言中执行相同操作的信息

Many thanks非常感谢

There's a fairly comprehensive example creating an IfcWall element/object:有一个相当全面的例子来创建一个 IfcWall 元素/对象:

https://docs.xbim.net/examples/proper-wall-in-3d.html https://docs.xbim.net/examples/proper-wall-in-3d.html

and the full example in Github at https://github.com/xBimTeam/XbimSamples/blob/master/HelloWall/HelloWallExample.cs以及https://github.com/xBimTeam/XbimSamples/blob/master/HelloWall/HelloWallExample.cs的 Github 中的完整示例

That demonstrates the creating the object and a lot more besides (including geometry).这演示了创建 object 以及更多(包括几何)。 xbim Essentials lets you read and write the whole IFC schema, which can include the geometry. xbim Essentials 允许您读取和写入整个 IFC 模式,其中可以包括几何。 But if you just want to create an element it's pretty simple:但是,如果您只想创建一个元素,则非常简单:

IModel model = BuildModel(); // There's a bit of bootstrapping in the example to create the base model and define an IFC Project and Building

using (var txn = model.BeginTransaction("Create Wall"))
{
    var wall = model.Instances.New<IfcWallStandardCase>();
    wall.Name = "A Standard rectangular wall";
    // ...*snipped* everything else that create representation, placement, materials etc
    txn.Commit();   
    return wall;
}

Then it's just a matter of adding the wall element to the structure.然后只需将墙元素添加到结构中即可。 There's a helper for this used in the example to add the wall to the building:在示例中使用了一个助手来将墙添加到建筑物中:

using (var txn = model.BeginTransaction("Add Wall"))
{
    building.AddElement(wall);
    txn.Commit();
}

Lastly you'd save the model to an IFC Step file.最后,您将 model 保存到 IFC 步骤文件。

model.SaveAs("HelloWallIfc4.ifc", IfcStorageType.Ifc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM