Last active
November 17, 2021 23:53
-
-
Save gtfierro/251743d1e5da2142769fd15beee937e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rdflib import Namespace | |
from brickschema.namespaces import BRICK, RDF | |
from brickschema import Graph | |
NS = Namespace("ex:") | |
def ifc2brick(osobj): | |
""" | |
Convert an IFC object from OpenShell to a Brick object. | |
Returns the corresponding Brick graph for that object | |
""" | |
g = Graph() | |
g.bind("ns", NS) | |
attrs = osobj.get_info() | |
print(osobj, attrs) | |
entity = NS[attrs["GlobalId"]] | |
for brickClass, ifcDefn in brick2ifc.items(): | |
if osobj.is_a(ifcDefn["entity"]): | |
continue | |
for attr, value in ifcDefn.get("attributes", {}).items(): | |
if isinstance(value, list): | |
if attrs.get("PredefinedType") not in value: | |
continue | |
elif attrs.get("PredefinedValue", None) != value: | |
continue | |
g.add((entity, RDF.type, brickClass)) | |
return g | |
brick2ifc = { | |
BRICK.Camera: { | |
"entity": "IfcAudioVisualAppliance", | |
"attributes": { | |
"IfcAudioVisualApplianceType": "CAMERA", | |
}, | |
}, | |
BRICK.AHU: { | |
"entity": "IfcUnitaryEquipment", | |
"attributes": { | |
"IfcUnitaryEquipmentType": "AIRHANDLER", | |
}, | |
}, | |
BRICK.Boiler: { | |
"entity": "IfcBoiler", | |
}, | |
BRICK.CRAC: { | |
"entity": "IfcUnitaryEquipment", | |
"attributes": { | |
"IfcUnitaryEquipmentType": "AIRCONDITIONINGUNIT", | |
}, | |
}, | |
BRICK.Chiller: { | |
"entity": "IfcChiller", | |
}, | |
BRICK.Compressor: { | |
"entity": "IfcCompressor", | |
}, | |
BRICK.Condenser: { | |
"entity": "IfcCondenser", | |
}, | |
BRICK.Cooling_Tower: { | |
"entity": "IfcCoolingTower", | |
}, | |
BRICK.Damper: { | |
"entity": "IfcDamper", | |
}, | |
BRICK.Fan: { | |
"entity": "IfcFan", | |
}, | |
BRICK.Filter: { | |
"entity": "IfcFilter", | |
"attributes": { | |
# TODO: is this correct? | |
"IfcFilterType": "AIRPARTICLEFILTER", | |
}, | |
}, | |
BRICK.Heat_Exchanger: { | |
"entity": "IfcHeatExchanger", | |
}, | |
BRICK.Humidifier: { | |
"entity": "IfcHumidifier", | |
}, | |
BRICK.Pump: { | |
"entity": "IfcPump", | |
}, | |
BRICK.TerminalUnit: { | |
"entity": "IfcAirTerminalBox", | |
}, | |
BRICK.CAV: { | |
"entity": "IfcAirTerminalBox", | |
"attributes": { | |
"IfcAirTerminalBoxType": "CONSTANTFLOW", | |
}, | |
}, | |
BRICK.VAV: { | |
"entity": "IfcAirTerminalBox", | |
"attributes": { | |
"IfcAirTerminalBoxType": ["VARIABLEFLOWPRESSUREDEPENDANT" ",VARIABLEFLOWPRESSUREINDEPENDANT"], | |
}, | |
}, | |
BRICK.Valve: { | |
"entity": "IfcValve", | |
# TODO: how to get the "substance" flowing through valve? connect to IFC system? | |
}, | |
BRICK.Thermostat: { | |
"entity": "IfcUnitaryControlElement", | |
"attributes": { | |
"IfcUnitaryControlElementType": "THERMOSTAT", | |
}, | |
}, | |
BRICK.Weather_Station: { | |
"entity": "IfcUnitaryControlElement", | |
"attributes": { | |
"IfcUnitaryControlElementType": "WEATHERSTATION", | |
}, | |
}, | |
# lighting | |
BRICK.Luminaire: { | |
"entity": "IfcLightFixture", | |
}, | |
BRICK.Meter: { | |
"entity": "IfcFlowMeter", | |
}, | |
BRICK.Electric_Meter: { | |
"entity": "IfcFlowMeter", | |
"attributes": { | |
"IfcFlowMeterType": "ENERGYMETER", | |
}, | |
}, | |
BRICK.Gas_Meter: { | |
"entity": "IfcFlowMeter", | |
"attributes": { | |
"IfcFlowMeterType": "GASMETER", | |
}, | |
}, | |
BRICK.Water_Meter: { | |
"entity": "IfcFlowMeter", | |
"attributes": { | |
"IfcFlowMeterType": "WATERMETER", | |
}, | |
}, | |
BRICK.Motor: { | |
"entity": "IfcElectricMotor", | |
}, | |
BRICK.PV_Panel: { | |
"entity": "IfcSolarDevice", | |
"attributes": { | |
"IfcSolarDeviceType": "SOLARPANEL", | |
}, | |
}, | |
# Locations | |
BRICK.Building: { | |
"entity": "IfcBuilding", | |
}, | |
BRICK.Floor: { | |
"entity": "IfcBuildingStorey", | |
}, | |
BRICK.Space: { | |
"entity": "IfcSpace", | |
}, | |
BRICK.Zone: { | |
"entity": "IfcSpatialZone", | |
}, | |
BRICK.HVAC_Zone: { | |
"entity": "IfcSpatialZone", | |
"attributes": { | |
"IfcSpatialZoneType": "THERMAL", | |
}, | |
}, | |
BRICK.Lighting_Zone: { | |
"entity": "IfcSpatialZone", | |
"attributes": { | |
"IfcSpatialZoneType": "LIGHTING", | |
}, | |
}, | |
} | |
if __name__ == "__main__": | |
import ifcopenshell | |
ifc_file = ifcopenshell.open('path/to/ifc/file.ifc') | |
# if you want to use this w/ blenderbim | |
# import blenderbim.tool as tool | |
# ifc_file = tool.Ifc.get() | |
#o = ifc_file.create_entity("IfcSpace") | |
#print(o) | |
g = Graph() | |
for element in ifc_file.by_type("IfcElement") + ifc_file.by_type("IfcSpatialStructureElement"): | |
b = ifc2brick(element) | |
if len(b): | |
g += b | |
g.serialize('test.ttl', format="turtle") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment