### Install Xbim.Essentials via Package Manager Console Source: https://github.com/xbimteam/xbimessentials/blob/master/README.md Command to install the Xbim.Essentials NuGet package using the Package Manager Console. Note that Xbim.Essentials is a meta package; for more control, add dependent packages directly. ```powershell PM> Install-Package Xbim.Essentials ``` -------------------------------- ### Reading Data from an IFC File Source: https://github.com/xbimteam/xbimessentials/blob/master/README.md This example demonstrates reading an IFC file using IfcStore.Open, querying doors with LINQ, retrieving a specific door by its GlobalId, and extracting its properties. The output shows the door's ID, name, and a list of property name-value pairs. ```csharp const string fileName = "SampleHouse.ifc"; using (var model = IfcStore.Open(fileName)) { // get all doors in the model (using IFC4 interface of IfcDoor - this will work both for IFC2x3 and IFC4) var allDoors = model.Instances.OfType(); // get only doors with defined IIfcTypeObject var typedDoors = model.Instances.Where(d => d.IsTypedBy.Any()); // get one single door by its unique identifier / guid var id = "2AswZfru1AdAiKfEdrNPnu"; var theDoor = model.Instances.FirstOrDefault(d => d.GlobalId == id); Console.WriteLine($"Door ID: {theDoor.GlobalId}, Name: {theDoor.Name}"); // get all basic properties of the door var properties = theDoor.IsDefinedBy .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet) .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties) .Select(p => p as IIfcPropertySingleValue); foreach (var property in properties) Console.WriteLine($"Property: {property.Name}, Value: {property.NominalValue}"); } ``` ```text Door ID: 3cUkl32yn9qRSPvBJVyWYp, Name: Doors_ExtDbl_Flush:1810x2110mm:285860 Property: IsExternal, Value: true Property: Reference, Value: 1810x2110mm Property: Level, Value: Level: Ground Floor Property: Sill Height, Value: 0 Property: Area, Value: 4.9462127188431 Property: Volume, Value: 0.193819981582386 Property: Mark, Value: 1 Property: Category, Value: Doors Property: Family, Value: Doors_ExtDbl_Flush: 1810x2110mm Property: Family and Type, Value: Basic Wall: Wall-Ext_102Bwk-75Ins-100LBlk-12P Property: Type, Value: 1810x2110mm Property: Phase Created, Value: New Construction ``` -------------------------------- ### Amending Data in an IFC File Source: https://github.com/xbimteam/xbimessentials/blob/master/README.md This example shows how to modify an IFC file by opening it with editor credentials, retrieving a door, creating a new property set with a purchase cost property, changing the door's name, and committing the transaction. ```csharp const string fileName = "SampleHouse.ifc"; var editor = new XbimEditorCredentials { ApplicationDevelopersName = "EZ Bim Apps Inc", ApplicationFullName = "My BIM App", ApplicationIdentifier = "my-bim-app", ApplicationVersion = "1.0", EditorsFamilyName = "John", EditorsGivenName = "Doe", EditorsOrganisationName = "Acme Consultants Inc" }; using (var model = IfcStore.Open(fileName, editor, true)) { // get an existing door from the model var theDoor = model.Instances.FirstOrDefault(d => d.GlobalId == id); // open transaction for changes using (var txn = model.BeginTransaction("Doors modification")) { // create new property set to host properties var pSetRel = model.Instances.New(r => { r.GlobalId = Guid.NewGuid(); r.RelatingPropertyDefinition = model.Instances.New(pSet => { pSet.Name = "Commercial"; pSet.HasProperties.Add(model.Instances.New(p => { p.Name = "PurchaseCost"; p.NominalValue = new IfcMonetaryMeasure(200.00); // Default Currency set on IfcProject })); }); }); // change the name of the door theDoor.Name += "_costed"; // add properties to the door pSetRel.RelatedObjects.Add(theDoor); // commit changes txn.Commit(); } } ``` -------------------------------- ### Generate geometry and export to wexBIM/XBIM with Xbim3DModelContext Source: https://github.com/xbimteam/xbimessentials/blob/master/README.md Generates 3D geometry from an IFC file using Xbim3DModelContext, then optionally exports to wexBIM for web viewing and saves to the internal XBIM format. Requires the Xbim.Geometry package, which is Windows-only and uses a native C++ geometry engine for boolean/CSG operations. Geometry generation can take seconds or minutes for larger models. ```csharp const string fileName = @"SampleHouse4.ifc"; var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM"); var xbimDbFilename = Path.ChangeExtension(fileName, "xBIM"); using (var model = IfcStore.Open(fileName)) { // IFC file is already parsed and open. Now build the 3D var context = new Xbim3DModelContext(model); context.CreateContext(); // Creates the Geometry using native GeometryEngine // Optional: Export to 'wexbim' format for use in WebUI's xViewer - geometry only using (var wexBimFile = File.Create(wexBimFilename)) { using (var wexBimBinaryWriter = new BinaryWriter(wexBimFile)) { model.SaveAsWexBim(wexBimBinaryWriter); wexBimBinaryWriter.Close(); } wexBimFile.Close(); } // Save IFC to the internal XBIM format, which includes geometry model.SaveAs(xbimDbFilename, StorageType.Xbim); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.