Using IfcOpenshell and pythonOCC to generate cross sections directly from an IFC file

[This article contains several snippets of source code for illustration purposes, the full source code can be downloaded at the bottom]

Section information can be used for multiple purposes. This example is the first part of a project in which the aim is to be able to directly send information to a large 3D concrete printer. This printer will be able to print concrete buildings on a 1:1 scale on a building site. The goal is to control the printer directly from an IFC model. Since the printer will print one layer at a time, the first step is to derive section information from an IFC file. This is what this tutorial is about. As an example of the information that can be deduced from a section, the area that needs to be printed is calculated.

This example builds upon some of the concepts in "Using IfcOpenShell and pythonOCC to construct new geometry" and uses the same model of a simple house, called IfcOpenHouse.

Read more…

Using the parsing functionality of IfcOpenShell interactively

In this recipe we are going to look at an interactive way of working with Python and IfcOpenShell that allows to quickly explore the possibilities offered by the tools. When the python interpreter (python.exe) is executed without arguments it will function as a REPL (a Read Evaluate Print Loop). It enables the user to type a single line of code and immediately see the evaluated result. An example of such a session is provided below. It outlines the procedure of starting with an IfcProject and descending down to the unit for angular measures. In this particular file it seems that angles are specified as degrees, a constant factor of 0.0174533 away from radians.

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ifcopenshell
>>> file = ifcopenshell.open("IfcOpenHouse.ifc")
>>> project = file.by_type("IfcProject")[0]
>>> project
#18=IfcProject('2f0veX5Vj59AhEg6WqGnhO',#5,'IfcOpenHouse',$,$,$,$,(#11),#17)
>>> project.is_a()
'IfcProject'
>>> project.is_a("IfcRoot")
True
>>> project.is_a("IfcWall")
False
>>> project.id()
18
>>> project.attribute_name(0)
'GlobalId'
>>> project.attribute_type(0)
'STRING'
>>> project.GlobalId
'2f0veX5Vj59AhEg6WqGnhO'
>>> project.Bier
Traceback (most recent call last):
  File "", line 1, in 
  File "ifcopenshell\\ifcopenshell.py", line 28, in __getattr__
    except: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name))
AttributeError: entity instance of type 'IfcProject' has no attribute 'Bier'
>>> project.UnitsInContext
#17=IfcUnitAssignment((#13,#16))
>>> units = project.UnitsInContext.Units
>>> angle_unit = filter(lambda u: u.UnitType == "PLANEANGLEUNIT", units)[0]
>>> angle_unit
#16=IfcConversionBasedUnit(#12,.PLANEANGLEUNIT.,'Degrees',#15)
>>> angle_unit.ConversionFactor
#15=IfcMeasureWithUnit(IfcPlaneAngleMeasure(0.0174533),#14)
>>> angle_unit.ConversionFactor.ValueComponent
IfcPlaneAngleMeasure(0.0174533)
>>> angle_unit.ConversionFactor.ValueComponent.is_a()
'IfcPlaneAngleMeasure'
>>> angle_unit.ConversionFactor.ValueComponent.wrappedValue
0.0174533

Using IfcOpenShell and pythonOCC to construct new geometry

[This article contains several snippets of source code for illustration purposes, the full source code can be downloaded at the bottom]

In this short exercise we are going to build on top the IfcOpenHouse model. It is one of the first IFC models entirely built using program code. It is a nice model, but it has a few shortcomings: for example, it does not define an IfcSpace instance that describes the interior space bounded by the walls and roof. In this exercise we are going to model the geometry of this space automatically from the geometry of the bounding elements and calculate the interior volume of the model.

The IfcOpenHouse model as imported into a regular CAD application

The IfcOpenHouse model as imported into a regular CAD application

Read more…