Skip to content

Instantly share code, notes, and snippets.

@aahoo
Last active January 9, 2017 14:45
Show Gist options
  • Save aahoo/c97248816510bf9892a2e8bdf90d1626 to your computer and use it in GitHub Desktop.
Save aahoo/c97248816510bf9892a2e8bdf90d1626 to your computer and use it in GitHub Desktop.
Extracting building envelope elements in IFC using IfcOpenShell and BIMserver
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extracting building envelope elements in IFC\n",
"\n",
"## Using [IfcOpenShell](https://github.com/IfcOpenShell/IfcOpenShell)\n",
"\n",
"[There are at least three ways to approach this problem](https://github.com/IndustryFoundationClasses/Questions/issues/9): `IsExternal` flag, examining space boundary relationships, and geometry analysis. The first method will be used here. Note that the author of the IFC model may have not set this flag, therefore, it is not guaranteed to find all the external building element instances with this approach.\n",
"\n",
"We want to find `IfcBuildingElement`s that have the `IsExternal` flag set to true. It sounds simple, but it is actually quite complicated. `IsExternal` is not explicitly defined as an attribute of `IfcBuildingElement`. Instead, we should look for an instance of `IfcPropertySingleValue` with its `Name` attribute equal to `IsExternal` and `NominalValue` attribute set to `True`. Here, we will assign this instance to `extPropertySingleValue` variable.\n",
"\n",
"We can either start from `IfcPropertySingleValue` or from `IfcBuildingElement`. Both of these pathes are shown below but the code is only written for the former path.\n",
"\n",
"### The path from IfcBuildingElement to extPropertySingleValue\n",
"```\n",
"(IfcBuildingElement) -IsDefinedBy->\n",
"(IfcRelDefinesByProperties) -RelatingPropertyDefinition->\n",
"(IfcPropertySet) -HasProperties->\n",
"(extPropertySingleValue)\n",
"```\n",
"*Entities are encloded in parents and relationships are enclosed with dashes and an arrow showing the direction of the relationship.*\n",
"\n",
"*`IsDefinedBy` is an [inverse attribte](https://en.wikipedia.org/wiki/EXPRESS_%28data_modeling_language%29#Entity-Attribute). `RelatingPropertyDefinition` and `HasProperties` are explicit attributes.*\n",
"\n",
"### The path from extPropertySingleValue to IfcBuildingElement\n",
"```\n",
"(extPropertySingleValue) -PartOfPset->\n",
"(IfcPropertySet) -DefinesOccurrence->\n",
"(IfcRelDefinesByProperties) -RelatedObjects->\n",
"(IfcBuildingElement)\n",
"```\n",
"\n",
"*`PartOfPset` and `DefinesOccurrence` are [inverse attribtes](https://en.wikipedia.org/wiki/EXPRESS_%28data_modeling_language%29#Entity-Attribute). `RelatedObjects` is an explicit attribte.*\n",
"\n",
"Donwload the IFC file from [here](http://projects.buildingsmartalliance.org/files/?artifact_id=4278) and extract it to `2011-09-14-Duplex-IFC` folder."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import ifcopenshell\n",
"ifcf = ifcopenshell.open(\"2011-09-14-Duplex-IFC/Duplex_A_20110907_optimized.ifc\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'Description': None,\n",
" 'Name': 'IsExternal',\n",
" 'NominalValue': IfcBoolean(.T.),\n",
" 'Unit': None,\n",
" 'id': 41,\n",
" 'type': 'IfcPropertySingleValue'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for psv in ifcf.by_type(\"IfcPropertySingleValue\"):\n",
" if psv.Name == \"IsExternal\" and psv.NominalValue.wrappedValue == True: \n",
" extPropertySingleValue = psv\n",
"extPropertySingleValue.get_info()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'Description': None,\n",
" 'GlobalId': '3qRT93CWv5Ueh9Gf9PrSJc',\n",
" 'HasProperties': (#578=IfcPropertySingleValue('Reference',$,IfcLabel('M_Fixed:819mm x 759mm'),$),\n",
" #41=IfcPropertySingleValue('IsExternal',$,IfcBoolean(.T.),$),\n",
" #79=IfcPropertySingleValue('FireRating',$,IfcLabel('FireRating'),$)),\n",
" 'Name': 'Pset_WindowCommon',\n",
" 'OwnerHistory': #1=IfcOwnerHistory(#18091,#8812,$,.NOCHANGE.,$,$,$,0),\n",
" 'id': 23549,\n",
" 'type': 'IfcPropertySet'}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"extPsets = extPropertySingleValue.PartOfPset\n",
"# print(json.dumps(WallCommonPSets, default=vars, indent=2)) # uncomment to see all\n",
"extPsets[0].get_info()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`extPropertySingleValue` can be part of:\n",
"\n",
"- Pset_WallCommon\n",
"- Pset_CurtainWallCommon\n",
"- Pset_DoorCommon\n",
"- Pset_WindowCommon\n",
"- ..."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Types of external Psets {'Pset_WallCommon', 'Pset_DoorCommon', 'Pset_WindowCommon'}\n"
]
}
],
"source": [
"print(\"Types of external Psets\", set([extPset.Name for extPset in extPsets]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*[IfcRelDefinesByProperties](http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifckernel/lexical/ifcreldefinesbyproperties.htm) is a (objectified) relationship that defines the relationships between property set definitions and objects (building elements in this case).*"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'Description': None,\n",
" 'GlobalId': '3AASn2h1H3auy9IbAEJO7a',\n",
" 'Name': None,\n",
" 'OwnerHistory': #1=IfcOwnerHistory(#18091,#8812,$,.NOCHANGE.,$,$,$,0),\n",
" 'RelatedObjects': (#229=IfcWindow('1hOSvn6df7F8_7GcBWlSga',#1,'M_Fixed:819mm x 759mm:819mm x 759mm:147994',$,'819mm x 759mm',#17703,#18760,'147994',0.758999999999998,0.8189999999999998),),\n",
" 'RelatingPropertyDefinition': #23549=IfcPropertySet('3qRT93CWv5Ueh9Gf9PrSJc',#1,'Pset_WindowCommon',$,(#578,#41,#79)),\n",
" 'id': 26598,\n",
" 'type': 'IfcRelDefinesByProperties'}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"extPSetOccurences = [do for extPset in extPsets for do in extPset.DefinesOccurrence]\n",
"extPSetOccurences[0].get_info()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"49"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"extElements = [ro for occurence in extPSetOccurences for ro in occurence.RelatedObjects]\n",
"len(extElements)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '2800mm x 2410mm'),\n",
" ('IfcWindow', '750mm x 2200mm'),\n",
" ('IfcWindow', '750mm x 2200mm'),\n",
" ('IfcWindow', '750mm x 2200mm'),\n",
" ('IfcWindow', '750mm x 2200mm'),\n",
" ('IfcWindow', '4835mm x 2420mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '2800mm x 2410mm'),\n",
" ('IfcWindow', '4835mm x 2420mm'),\n",
" ('IfcDoor', '1250mm x 2010mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '2800mm x 2410mm'),\n",
" ('IfcDoor', '1250mm x 2010mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcDoor', '0813 x 2420mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '2800mm x 2410mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcDoor', '0813 x 2420mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWindow', '819mm x 759mm'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (435mm):207146'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (417mm):128676'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (417mm):128676'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWall',\n",
" 'Basic Wall:Party Wall - CMU Residential Unit Dimising Wall:128555'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (417mm):128676'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (417mm):128676'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (435mm):207146'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase',\n",
" 'Basic Wall:Party Wall - CMU Residential Unit Dimising Wall:128555'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Foundation - Concrete (435mm):207146'),\n",
" ('IfcWallStandardCase',\n",
" 'Basic Wall:Party Wall - CMU Residential Unit Dimising Wall:128555'),\n",
" ('IfcWallStandardCase', 'Basic Wall:Exterior - Brick on Block:130892'),\n",
" ('IfcWallStandardCase',\n",
" 'Basic Wall:Party Wall - CMU Residential Unit Dimising Wall:128555')]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[(e.is_a(), e.ObjectType) for e in extElements]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using [BIMserver](https://github.com/opensourceBIM/BIMserver)\n",
"\n",
"```\n",
"{\n",
" \"type\": \"IfcBuildingElement\",\n",
" \"includeAllSubtypes\": true,\n",
" \"properties\": {\n",
" \"IsExternal\": true\n",
" }\n",
"}\n",
"```"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment