IfcOpenShell

Description
IfcOpenShell is an open source (LGPL 3) software library that helps developers work with the industry foundation classes (IFC) file format. The IFC file format can be used to describe building and construction data. The format is commonly used for building information modelling (BIM), for example, mechanical loading analysis and thermal studies. IfcOpenShell is primarily a collection of C++ libraries, however, as it has Python bindings, it can be easily integrated with programs like FreeCAD and Blender.

IfcOpenShell uses OpenCASCADE internally to convert the implicit geometry in IFC files into explicit geometry that other CAD packages can understand.

As of v0.19, FreeCAD is able to import IFC files as long as the Python module is available in the system. Likewise, the Arch and BIM Workbenches can export a building model to the IFC format so that it can be used in other applications.

To verify that IfcOpenShell is installed in your system, try to import it from the Python console; the library is correctly installed if no error message is returned.

Installation
IfcOpenShell can be installed in various ways depending on your operating system and Python environment.

Conda
For Windows and MacOS systems, FreeCAD distributions put together with the Conda package manager usually include IfcOpenShell already so no further installation is necessary. Get the appropriate distribution from the Download page.

The AppImage for Linux is also based on Conda, and it also includes IfcOpenShell.

Linux
You may install IfcOpenShell from your distribution's package manager, if it is available.

However, please notice that packages provided by a Linux repository tend to be old, and not contain the latest developments in the software. If you want to be sure you are using the newest software, use a Conda-based distribution of FreeCAD, a pre-compiled IfcOpenShell distribution, or compile IfcOpenShell yourself.

Using a pre-compiled distribution
There is a special repository of the IfcOpenShell project that compiles regularly the IfcOpenShell libraries for various systems (Linux, Windows, MacOS), architectures (32-bit and 64-bit), and Python versions (2.7, 3.x). To use these pre-compiled libraries, you must pick the right version that matches your operating system, architecture, and the major and minor numbers for the Python that is used with FreeCAD. This means that the first two numbers must match (Python 3.6 and 3.7 are distinct versions) while the third one (micro) does not matter (Python 3.6.5 and 3.6.12 are considered to be the same for compatibility purposes).


 * 1) Head to the build repository IfcOpenBot/IfcOpenShell. This repository is not for development, it only contains a copy of the main repository as well as pre-compiled packages.
 * 2) As of this writing (2020), the master branch of the IfcOpenShell project does not contain the latest code, so we need to select the desired branch, for example, v0.6.0.
 * 3) Click of the commit number, which will take you to the list of commits for the branch, for example, IfcOpenBot/IfcOpenShell/commits/v0.6.0.
 * 4) Go back in the history until you find a commit that has a comment. This will indicate the moment were pre-compiled libraries were released.
 * 5) Click on the commit. You will see a comment by IfcOpenBot showing a table of combinations of operating system, architecture, and Python version. Choose the right link to match your version of FreeCAD.
 * 6) The downloaded package needs to be extracted into a directory that is searched by Python to find modules.

Compiling
Compiling IfcOpenShell is recommended only for advanced users. The process uses the CMake configuration tool to produce a custom Makefile for use with the Make tool. The general instructions are outlined in the code repository.

The general steps are as follows:
 * 1) Get the source code of IfcOpenShell from its main repository.
 * 2) Gather all dependencies for compiling, including installing a C++ compiler, CMake, and Make, and the development files for Boost, libxml2, OpenCASCADE, SWIG, Python, and OpenCOLLADA (optional). Most of these components are strictly optional, however, for use with FreeCAD they should all be installed except for OpenCOLLADA, as it only provides support for DAE files.
 * 3) Run  to generate a, then compile the libraries by running.
 * 4) Install the  Python module in the appropriate  directory so that it is found by FreeCAD.

Prerequisites
Get the source code of the project and place it in a custom directory to which you have full write access.

As of this writing (2020), the master branch of the IfcOpenShell project does not contain the latest code, so we need to clone a specific branch.

Install the basic compilation tools.

OpenCASCADE
Install the development files of OpenCASCADE.

Which expands to

You may use the community edition (OCE) of OpenCASCADE as well, however, please notice that this version is old and no longer recommended by FreeCAD as of 2020.

Python wrapper
For usage with FreeCAD you need the Python wrapper which uses SWIG to generate the proper interfaces from the C++ classes.

CMake configuration
It is recommended to perform the compilation in a specific build directory.

Notice that the file that drives CMake is inside the  directory.

Depending on your Linux distribution, and the way you installed the dependencies, you may have to define some CMake variables so that the proper libraries are found.

Specifying the OpenCASCADE libraries
If you manually compiled OpenCASCADE, or if the libraries are not in a standard directory, you may have to set up the proper variables.

Specifying the libxml2 libraries
If the libxml2 libraries are not found, or if the libraries are not in a standard directory, you may have to set up the proper variables.

Without OpenCOLLADA
If you don't need OpenCOLLADA support you need to turn it off explicitly.

With OpenCOLLADA
If you manually compiled OpenCOLLADA, or if the libraries are not in a standard directory, you may have to set up the proper variables.

Troubleshooting and other options
All configuration options are available in the file located inside the  directory. You may look for other options that can be set here if there are problem when running CMake.

Installing
If the configuration doesn't report any error, you may install the compiled shared and static libraries to the corresponding directories.

By default, the is, so all compiled files will be tried to be installed to this directory, which normally requires elevated privileges.

In similar way, the Python wrapper will be placed in

Related

 * Website: ifcopenshell.org
 * Code repository: IfcOpenShell/IfcOpenShell
 * Academy with examples and articles: academy.ifcopenshell.org
 * OSArch community with resources for open source architecture: wiki.OSArch.org
 * Compiling IfcOpenShell for MacOS; a guide that describes the general process. It may not be needed any more as IfcOpenShell is now distributed together with FreeCAD thanks to Conda.
 * What pages link to this page.