IfcOpenShell/en

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 IfcOpenShell package
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 considered 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,.
 * 3) Click on the commit number, which will take you to the list of commits for the branch, for example,.
 * 4) Go back in the history until you find a commit that has a comment. This will indicate the moment when 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 for "Python" to match your version of FreeCAD. The "Blender", "IfcConvert", and "IfcGeomServer" packages are not needed for FreeCAD usage.
 * 6) The downloaded package needs to be extracted, and the extracted directory needs to be moved to a directory that is searched by Python to find modules.


 * The search path can be found by inspecting the variable in the Python console.


 * If you'd like to install the IfcOpenShell library only for your normal user, and not affect system libraries, you should place the extracted folder in the user's home directory.


 * If you'd like to install the IfcOpenShell library system-wide, you typically need superuser privileges to write to system directories; this is usually a directory, or a  directory for Debian/Ubuntu distributions.

If the directory is correctly moved, test that the module is accessible from the Python console.

To remove the installed library, just remove the corresponding directory.

Compiling
Compiling IfcOpenShell is recommended only for advanced users. The process is similar to compiling FreeCAD on Linux, so if you have done this already, then you may already have the necessary requisites like OpenCASCADE's development files. The process uses the CMake configuration tool to produce a custom for use with the Make tool. The general instructions are outlined in the IfcOpenShell 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 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 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 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 problems when running CMake.

Compiling
If there were no error messages you can proceed to compile the libraries by running, where is the number of processors that you want to assign to the compilation. Choose at least one less than the total number of CPU cores that you have.

Installing
If the compilation doesn't report any error, you may install the compiled shared and static libraries, as well as the Python wrapper to the corresponding directories.

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

In similar way, the Python wrapper will be placed in a directory, or a  directory for Debian/Ubuntu distributions.

More information

 * 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.
 * IFC installation; discussion in the forum.
 * What pages link to this page.