Code Monkey home page Code Monkey logo

ifcsharplibrary's Introduction

IfcSharpLibrary

The C#-Library of IfcSharp contains interfaces to the IFC-model of buildingSMART, which is described here.

Introduction

Create a simple IFC file

The creation of an IFC file requires only a few lines of code. The underlying class model has the same structure as the IFC data model and therby enforcing the definitions of the corresponding IFC Schema (2X3, 4.0 etc.) The advantage of this early-binding approach is that errors in an IFC model can be handled at compile time rather than at runtime (late-binding).

// create a new ifc.Model which stores all ifc.ENTITY data inside the ifc.Repository.CurrentModel
ifc.Repository.CurrentModel = new ifc.Model(Name: "hello_project_output"); 

// create a new ifc.Project, this implicitly appends the ifc.ENTITY to ifc.Repository.CurrentModel 
// NOTE: every ifc.ENTITY has an EndOfLineComment which can be used as a comment for STEP files
ifc.Project project = new ifc.Project(Name: new ifc.Label("my first ifc-project"), EndOfLineComment: "creating the project");

// IfcSharpLibrary also takes care of creating the GlobalId if you simple pass 'null'
ifc.Building building = new ifc.Building(GlobalId: null, Name: new ifc.Label("my first ifc-building"));

// due to reflection ifc.ENTITY objects which have no parent dont need to be assigned it to a variable
new ifc.RelAggregates(RelatingObject: project, RelatedObjects: new ifc.Set1toUnbounded_ObjectDefinition(building));

// write the current state of the ifc.Repository.CurrentModel to a STEP file
// the output path defaults to ifc.Model.Name (in this case 'hello_project_output.ifc')
ifc.Repository.CurrentModel.ToStepFile(); 

Several IFC versions are supported (see Supported IFC Schemas). All IFC versions use the same read and write routines. The read and write routines use the Reflection mechanism. This avoids that for each class a separate read or write routine must be kept. The IfcStep export therefore comprises only a few lines of code, since it evaluates the IFC schema mapped in the C# class library in a general valid manner via Reflection.
This mechanism is also used to keep track of all ifc.ENTITY instances in memory and write them to a file or database. This means that once you assigned a ifc.Repository.CurrentModel at runtime you can just instantiate objects from anywhere in your project. This makes IfcSharpLibrary a very sleek solution as it is reduces the overhead of assigning every single ifc.ENTITY to its parent.

Export capabilities

With the IfcSharp Library you can write IFC-models by C#-code or read and write to different formats, like this:

ifc.Repository.CurrentModel.ToStepFile();  // creates hello_project_output.ifc (step-format)
ifc.Repository.CurrentModel.ToHtmlFile();  // creates hello_project_output.html in step-format with syntax highlighting
ifc.Repository.CurrentModel.ToCsFile();    // creates hello_project_output.cs with c# code (useful for creating code from existing files)
ifc.Repository.CurrentModel.ToSqliteFile();// creates hello_project_output.sqlite3 with the default option exportCompleteSchema=false 
ifc.Repository.CurrentModel.ToXmlFile();   // creates hello_project_output.ifcXml
ifc.Repository.CurrentModel.ToSqlFile();   // creates SQL for ifcSQL without server-connection
ifc.Repository.CurrentModel.ToSql(ServerName: System.Environment.GetEnvironmentVariable("SqlServer"), 
                                  DatabaseName: "ifcSQL",
                                  ProjectId: 3,
                                  WriteMode: ifc.Model.eWriteMode.OnlyIfEmpty); // SQL server connection required

One of these Formats is ifcSQL, that ist not intended to transport Models form A to B. It is instead intended to store and query models as a collection of digital twins (see IfcSql documentation).

Further examples

Please refer to examples listed in IfcSharpApps

Implementation details

General structure

IfcSharpLibrary can be broken down into three different components:

  1. IfcSharpCore: Implements general functionality (i.e. types, units, logging etc.)
  2. IfcSchema: Implementations for the different IFC schemas as C# classes (see IfcSchema documentation)
  3. IfcIO: Currently we support STEP, SQL, SQLite, CS, HTML and XML (some implementations are still in need for further development and testing)

This makes this library highly customizable and enables you to choose specifically which implementations you need.

Supported IFC Schemas

We currently support these IFC schemas:

NOTE: Due to the class model you can only include the IfcSchema for one IFC version. This means for multiple IFC versions you need to create multiple build-projects.

How to Install and Run the Project

Simply run git clone https://github.com/IfcSharp/IfcSharpLibrary.git.

To start off you can directly add a reference to the included IfcSharpLibrary.csproj file, which is configured to use the IFC4 bindings.

NOTE: The default IfcSharpLibrary.csproj project does not include the optional SQLite support. In order to use it you have to install the additional dependencies and include the files from IfcIO/IfcSqlite in your project (see also IfcSqlite README ).

After you included/created the project the ifc namespace should be available and you can start developing with IfcSharpLibrary.

Optional: IfcSqlite

See IfcSqlite documentation

Credits

Bernhard Simon Bock @bsbock
Friedrich Eder @friedrichEder

Licence

This project is licensed under the terms of this MIT license.

ifcsharplibrary's People

Contributors

bsbock avatar friedricheder avatar ifcsharp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ifcsharplibrary's Issues

Attempt to port to IfcOpenShell

I'm considering porting some of the work here to C++ and Python so that you can more easily cross platform import/export SQL and SQLite. Porting creates the risk of being out of sync with your repository. What are the plans in keeping the schema more or less stable, and how does this fit into the work of buildingSMART?

[Test] IFC2SQLite

Hi Friedrich, I made a small .exp test to map from IFC schema/spec to SQLite

test.zip

The requirements:

  1. Each TYPE and ENTITY type should be a table - without duplication (I don't care about inverses/relationships, so there's not a need to map relationships, just TYPES and ENTITY types as individual tables without mapping parent/child) - also I want to drop Ifc prefixes (IfcPerson = Person)
  2. A query that shows each ENTITY holds which ENTITY types (including inverses) but it won't be a table, it'd be just a list or something like that

IFCPARAMETERVALUE is not parsed.

#186= IFCTRIMMEDCURVE(#185,(IFCPARAMETERVALUE(269.874418757191)), IFCPARAMETERVALUE(285.07364578635)),.T.,.PARAMETER.);

This is a snippet of an IFC file which causes this error below.

ERROR on Parse2LIST.2:#186= IFCTRIMMEDCURVE(#185,(IFCPARAMETERVALUE(269.874418757191)),(IFCPARAMETERVALUE(285.07364578635)),.T.,.PARAMETER.);

Cannot parse IfcPropertySingleValue

When I try to read an IFC-file (pipe example) I get an error when parsing a PropertySingleValue:

"Die Länge darf nicht kleiner als 0 (null) sein.\r\nParametername: length"} | System.ArgumentOutOfRangeException

It is the "DN" value of the pipe ("400.0000") that is not working.

Read from step files: Errors

I tried to import different IFC-files; however I get some errors. Code looks like this:

ifc.Model helloProject = ifc.Model.FromStepFile("C:\\Users\\abc\\Documents\\AC20-FZK-Haus.ifc");

"Der Typ "Ifc.FacetedBrep " in der Assembly "IfcSharpLibrary, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null" konnte nicht geladen werden."

For other files I get a similar message concerning "Ifc.Value". (I used the "FZK house" model from https://www.ifcwiki.org/index.php?title=KIT_IFC_Examples)

IFC2X3

Hi Bernhard,

how do you generate a schema for IFC2X3, at moment it only seems to work for IFC4X2. I can see you can include / exclude schema, but not sure how it generates different ones?

Thank you

"ListElement_List2to2_LengthMeasure not supportet"

I'm trying some basic operations with this library, however, I get a few errors. I want to convert an IFC4-File to Sqlite using the following code lines:

Model CurrentModel = ifc.Model.FromStepFile("PATH_TO_FILE\\file.ifc");

CurrentModel.ToSqliteFile();

I receive the following errors (console)
TODO List++TYPE: Base=ListElement_List2to2_LengthMeasure not supportet in
followed by an IfcCartesianPointList2D. Is this not yet implemented or do I miss something here?

In Visual Studio I also get the following error:
$exception | {"Der Konstruktor für den Typ "ifc.Value" wurde nicht gefunden."} | System.MissingMethodException

How to use your library ?

Hi team, can I know the reason why this source missing, your team still working on process ?
I saw so many log can't resolve
image

Thank you

Duplicate globalId

After some attempts of writing IFC models to the sql server an entity is created twice (#3909 for me). Maybe a transaction problem? It happens for not successful write to database.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.