简体   繁体   中英

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#? I am trying to create objects based on class instances that result from a calculation which is coded in C#. The use of APIs of authoring software like Revit is not an option in this case.

I know only this resource, but it doesn't seem to contain a way of creating objects, only geometries: 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:

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

That demonstrates the creating the object and a lot more besides (including geometry). xbim Essentials lets you read and write the whole IFC schema, which can include the geometry. 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.SaveAs("HelloWallIfc4.ifc", IfcStorageType.Ifc);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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