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 and energy efficiency studies. IfcOpenShell is primarily a collection of C++ libraries, however, as it has Python bindings, it can be 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 ifcopenshell
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.
import ifcopenshell
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.
sudo apt install ifcopenshell
However, please notice that packages provided by a Linux repository tend to be old, and may 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).
- 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.
- 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
. - Click on the commit number, which will take you to the list of commits for the branch, for example,
IfcOpenBot/IfcOpenShell/commits/v0.6.0
. - 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.
- 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.
- The downloaded package needs to be extracted, and the extracted directory needs to be placed in the Python search path in order to find the new modules.
Note: the following examples assume a Debian/Ubuntu based system, but the general procedure should work for other operating systems.
- Unzipping the downloaded package creates an
ifcopenshell/
folder.
- Unzipping the downloaded package creates an
unzip ifcopenshell-python-36-v0.6.0-4baec57-linux64.zip
- The search path can be found by inspecting the
sys.path
variable in the Python console.
- The search path can be found by inspecting the
import sys
print(sys.path)
- If you'd like to install the IfcOpenShell library only for your user, and not affect system directories, you should place the extracted
ifcopenshell/
folder in your own user's home directory.
- If you'd like to install the IfcOpenShell library only for your user, and not affect system directories, you should place the extracted
mv -t $HOME/.local/lib/python3.6/site-packages/ ifcopenshell/
- 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
site-packages/
directory, or adist-packages/
directory for Debian/Ubuntu distributions.
- 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
sudo mv -t /usr/local/lib/python3.6/dist-packages/ ifcopenshell/
If the directory is correctly moved, test that the ifcopenshell
module is accessible from the Python console.
>>> import ifcopenshell
>>> print(ifcopenshell.version)
0.6.0b0
>>> print(ifcopenshell.__path__)
['/home/user/.local/lib/python3.6/site-packages/ifcopenshell']
To remove the installed library, just remove the corresponding directory with all modules inside.
rm -rf $HOME/.local/lib/python3.6/site-packages/ifcopenshell/
sudo rm -rf /usr/local/lib/python3.6/dist-packages/ifcopenshell/
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 the OpenCASCADE's development files. 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 IfcOpenShell repository, and are as follows:
- Get the source code of IfcOpenShell from its main repository.
- Gather all dependencies for compiling, including 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. OpenCOLLADA is optional as it only provides DAE support for the
IfcConvert
binary. - Run
cmake
to generate aMakefile
, then start the compilation by runningmake
. - Install the
ifcopenshell
Python module in the appropriatesite-packages/
directory so that it is found by FreeCAD.
Note: the following examples assume a Debian/Ubuntu based system, but the general procedure should work for other operating systems. For example, in Debian shared libraries are normally located in /usr/lib/x86_64-linux-gnu/
while in other distributions this may be /usr/lib64/
so the paths should be adjusted accordingly.
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.
git clone https://github.com/IfcOpenShell/IfcOpenShell -b v0.6.0 ifcopenshell-source
Install the basic compilation tools.
sudo apt install git cmake gcc g++ libboost-all-dev
OpenCASCADE
Install the development files of OpenCASCADE.
sudo apt install libocct*-dev
Which expands to
sudo apt install libocct-data-exchange-dev libocct-draw-dev libocct-foundation-dev libocct-modeling-algorithms-dev libocct-modeling-data-dev libocct-ocaf-dev libocct-visualization-dev
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.
OpenCOLLADA
Install the development files of OpenCOLLADA.
sudo apt install opencollada-dev
If the files are too old in your distribution, you may also compile the libraries yourself. The procedure is outlined in the main repository, KhronosGroup/OpenCOLLADA, and it's very straight forward as it only requires libpcre3
and libxml2
as requisites.
sudo apt-get install libpcre3-dev libxml2-dev
git clone https://github.com/KhronosGroup/OpenCOLLADA OpenCOLLADA-source
mkdir -p OpenCOLLADA-build
cd OpenCOLLADA-build
cmake ../OpenCOLLADA-source
make -j 3
sudo make install
Python wrapper
For usage with FreeCAD you need the Python wrapper which uses SWIG to generate the proper interfaces from the C++ classes.
sudo apt-get install python-all-dev swig
CMake configuration
It is recommended to perform the compilation in a specific build directory.
mkdir -p ifcopenshell-build
cd ifcopenshell-build
cmake ../ifcopenshell-source/cmake/
Notice that the CMakeLists.txt
file that drives CMake is inside the cmake/
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.
cmake \
-DOCC_INCLUDE_DIR=/usr/include/opencascade \
-DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
../ifcopenshell-source/cmake/
By default the build system expects the community edition (OCE) of OpenCASCADE to be installed in /usr/include/oce/
, however, please notice that this version is old and no longer recommended by FreeCAD as of 2020. This is the reason that installing the development files of the main version of OpenCASCADE (OCCT) is recommended.
Without OpenCOLLADA
If you don't need OpenCOLLADA support you need to turn it off explicitly.
cmake \
-DOCC_INCLUDE_DIR=/usr/include/opencascade \
-DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
-DCOLLADA_SUPPORT=FALSE \
../ifcopenshell-source/cmake/
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 for OpenCOLLADA and for the libpcre
library.
cmake \
-DOCC_INCLUDE_DIR=/usr/include/opencascade \
-DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
-DOPENCOLLADA_INCLUDE_DIR=/usr/include/opencollada \
-DOPENCOLLADA_LIBRARY_DIR=/usr/lib/opencollada \
-DPCRE_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
../ifcopenshell-source/cmake/
Specifying the libxml2 libraries
If the libxml2
libraries are not found during compilation and linking, or if the libraries are not in a standard directory, you may have to set the proper variables.
cmake \
-DOCC_INCLUDE_DIR=/usr/include/opencascade \
-DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
-DCOLLADA_SUPPORT=FALSE \
-DLIBXML2_INCLUDE_DIR=/usr/include/libxml2 \
-DLIBXML2_LIBRARIES=/usr/lib/x86_64-linux-gnu/libxml2.so \
../ifcopenshell-source/cmake/
Specifying installation in the user's home directory
By default, the Python wrapper will be installed in a system site-packages/
directory, so it requires superuser privileges. By setting the USERSPACE_PYTHON_PREFIX
variable, the installation of the Python module will be done to the user's home directory.
cmake \
-DOCC_INCLUDE_DIR=/usr/include/opencascade \
-DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
-DCOLLADA_SUPPORT=FALSE \
-DLIBXML2_INCLUDE_DIR=/usr/include/libxml2 \
-DLIBXML2_LIBRARIES=/usr/lib/x86_64-linux-gnu/libxml2.so \
-DUSERSPACE_PYTHON_PREFIX=ON \
../ifcopenshell-source/cmake/
Specifying Python version
If you want to generate a binding for a particular Python version, set the PYTHON_EXECUTABLE
variable to the specific executable. Remember that this version must be the same Python version against which FreeCAD was compiled.
cmake \
...
-DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
../ifcopenshell-source/cmake/
Actual compilation
If there were no error messages during configuration with CMake, a Makefile
should have been created in the build directory, so you can proceed to compile the libraries by running make
.
make -j N
N
is the number of processors that you assign to the compilation process; choose at least one fewer than the total number of CPU cores that you have.
Testing the compilation in the build directory
In the build directory there should be a test file that can be run through the IfcConvert
program to output a mesh file, either OBJ or DAE if OpenCOLLADA support was enabled during compilation.
./IfcConvert IfcOpenHouse.ifc
If no output file is specified, by default it will create an OBJ file and its accompanying material table (MTL).
Installation of compiled libraries
If the compilation doesn't report any errors, you may install the headers, compiled libraries, as well as the Python wrapper to the corresponding directories.
sudo make install
By default, the CMAKE_INSTALL_PREFIX
is /usr/local/
, so all compiled files will be installed to this directory, which normally requires elevated privileges.
/usr/local/bin/IfcConvert
/usr/local/bin/IfcGeomServer
/usr/local/include/ifcparse/*.h
/usr/local/include/ifcgeom/*.h
/usr/local/include/ifcgeom_schema_agnostic/*.h
/usr/local/include/serializers/{*.h,*.cpp}
/usr/local/include/serializers/schema_dependent/{*.h,*.cpp}
/usr/local/lib/libIfcGeom.a
/usr/local/lib/libIfcGeom_*.a
/usr/local/lib/libIfcParse.a
/usr/local/lib/libSerializers.a
/usr/local/lib/libSerializers_*.a
In similar way, the Python wrapper will be placed in a site-packages/
directory, or a dist-packages/
directory for Debian/Ubuntu distributions.
/usr/lib/python3/dist-packages/ifcopenshell/
If the USERSPACE_PYTHON_PREFIX
variable was set during the CMake configuration step, the installation will be done to the user's site-packages/
directory.
$HOME/.local/lib/python3.6/site-packages/ifcopenshell/
Removing compiled libraries
To remove the installed libraries, just remove the corresponding files that were installed, and the ifcopenshell/
directory with all modules inside.
sudo rm -rf /usr/local/bin/IfcConvert
sudo rm -rf /usr/local/bin/IfcGeomServer
sudo rm -rf /usr/local/include/ifcparse/
sudo rm -rf /usr/local/include/ifcgeom/
sudo rm -rf /usr/local/include/ifcgeom_schema_agnostic/
sudo rm -rf /usr/local/lib/libIfcGeom*
sudo rm -rf /usr/local/lib/libIfcParse*
sudo rm -rf /usr/local/lib/libSerializers*
sudo rm -rf /usr/lib/python3/dist-packages/ifcopenshell/
Or if the USERSPACE_PYTHON_PREFIX
variable was set.
sudo rm -rf $HOME/.local/lib/python3.6/site-packages/ifcopenshell/
Manual installation
Compilation of the entire IfcOpenShell distribution produces the IfcConvert
and IfcGeomServer
binaries, as well as many static libraries, lib*.a
in the build directory. However, for FreeCAD we only need the Python wrappers generated inside the ifcwrap/
directory, and the Python modules in the original source directory under src/ifcopenshell-python/ifcopenshell/
.
- Produced by the compilation process:
../ifcopenshell-build/ifcwrap/ifcopenshell_wrapper.py
../ifcopenshell-build/ifcwrap/_ifcopenshell_wrapper.so
- Existing in the source directory:
../ifcopenshell-source/src/ifcopenshell-python/ifcopenshell/
The ifcopenshell
module is created by copying the original source directory, and adding the two *ifcopenshell_wrapper*
files to it.
cp -rt . ../ifcopenshell-source/src/ifcopenshell-python/ifcopenshell/
cp -t ifcopenshell/ ifcwrap/ifcopenshell_wrapper.py ifcwrap/_ifcopenshell_wrapper.so
Now this directory can be moved to the user-specific or system site-packages
to make it available for all Python applications.
mv -t $HOME/.local/lib/python3.6/site-packages/ ifcopenshell/
Or for system-wide installation:
sudo mv -t /usr/lib/python3/dist-packages/ ifcopenshell/
Troubleshooting and other options
All configuration options are available in the CMakeLists.txt
file located inside the ifcopenshell-source/cmake/
directory. You may look for other options that can be set here if there are problems when running CMake and Make.
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.
- Elements: Wall, Structure, Curtain Wall, Window, Roof, Space, Stairs, Equipment, Frame, Fence, Truss, Profile, Pipe, Pipe Connector
- Reinforcements: Straight Rebar, U-Shape Rebar, L-Shape Rebar, Stirrup, Bent-Shape Rebar, Helical Rebar, Column Reinforcement, Beam Reinforcement, Slab Reinforcement, Footing Reinforcement, Custom Rebar
- Panels: Panel, Panel Cut, Panel Sheet, Nest
- Materials: Material, Multi-Material
- Organization: Building Part, Project, Site, Building, Level, External reference, Section Plane, Schedule
- Axes: Axis, Axes system, Grid
- Modification: Cut with plane, Add component, Remove component, Survey
- Utilities: Component, Clone component, Split Mesh, Mesh to Shape, Select non-manifold meshes, Remove Shape from Arch, Close Holes, Merge Walls, Check, Toggle IFC Brep flag, 3 Views from mesh, Create IFC spreadsheet, Toggle Subcomponents
- Additional: Preferences, Import Export Preferences (IFC, DAE, OBJ, JSON, 3DS, SHP), IfcOpenShell, IfcPlusPlus, Arch API
- Materials: Solid, Fluid, Nonlinear mechanical, Reinforced (concrete); Material editor
- Element geometry: Beam (1D), Beam rotation (1D), Shell (2D), Fluid flow (1D)
Constraints
- Electromagnetic: Electrostatic potential, Current density, Magnetization
- Geometrical: Plane rotation, Section print, Transform
- Mechanical: Fixed, Displacement, Contact, Tie, Spring, Force, Pressure, Centrif, Self weight
- Thermal: Initial temperature, Heat flux, Temperature, Body heat source
- Overwrite Constants: Constant vacuum permittivity
- Solve: CalculiX Standard, Elmer, Mystran, Z88; Equations: Deformation, Elasticity, Electrostatic, Electricforce, Magnetodynamic, Magnetodynamic 2D, Flow, Flux, Heat; Solver: Solver control, Solver run
- Results: Purge, Show; Postprocessing: Apply changes, Pipeline from result, Warp filter, Scalar clip filter, Function cut filter, Region clip filter, Contours filter, Line clip filter, Stress linearization plot, Data at point clip filter, Filter function plane, Filter function sphere, Filter function cylinder, Filter function box
- Additional: Preferences; FEM Install, FEM Mesh, FEM Solver, FEM CalculiX, FEM Concrete; FEM Element Types
- Getting started
- Installation: Download, Windows, Linux, Mac, Additional components, Docker, AppImage, Ubuntu Snap
- Basics: About FreeCAD, Interface, Mouse navigation, Selection methods, Object name, Preferences, Workbenches, Document structure, Properties, Help FreeCAD, Donate
- Help: Tutorials, Video tutorials
- Workbenches: Std Base, Assembly, BIM, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Surface, TechDraw, Test Framework
- Hubs: User hub, Power users hub, Developer hub