Allow export of type relations in IFCCSV

This commit is contained in:
Dion Moult
2020-08-08 17:58:45 +10:00
parent 11a66ee181
commit 3292b98080
5 changed files with 32 additions and 200 deletions
@@ -2,6 +2,7 @@ import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.util.geolocation
import ifcopenshell.util.selector
import ifcopenshell.util.element
import bpy
import bmesh
import os
@@ -1272,19 +1273,10 @@ class IfcImporter():
new_prop.string_value = str(value)
def add_defines_by_type_relation(self, element, obj):
related_type = self.get_type(element)
related_type = ifcopenshell.util.element.get_type(element)
if related_type:
obj.BIMObjectProperties.relating_type = self.type_products[related_type.GlobalId]
# TODO: migrate into util function
def get_type(self, element):
if hasattr(element, 'IsTypedBy') and element.IsTypedBy:
return element.IsTypedBy[0].RelatingType
elif hasattr(element, 'IsDefinedBy') and element.IsDefinedBy: # IFC2X3
for relationship in element.IsDefinedBy:
if relationship.is_a('IfcRelDefinesByType'):
return relationship.RelatingType
def add_opening_relation(self, element, obj):
if not element.is_a('IfcOpeningElement'):
return
@@ -5,6 +5,7 @@ import json
import logging
import webbrowser
import ifcopenshell
import ifcopenshell.util.selector
import tempfile
from . import export_ifc
from . import import_ifc
@@ -2896,14 +2897,14 @@ class ExportIfcCsv(bpy.types.Operator):
def execute(self, context):
import ifccsv
self.filepath = bpy.path.ensure_ext(self.filepath, '.csv')
ifc_selector_parser = ifccsv.IfcSelectorParser()
ifc_selector_parser.ifc = bpy.context.scene.BIMProperties.ifc_file
ifc_selector_parser.query = bpy.context.scene.BIMProperties.ifc_selector
ifc_selector_parser.parse()
ifc_file = ifcopenshell.open(bpy.context.scene.BIMProperties.ifc_file)
selector = ifcopenshell.util.selector.Selector()
results = selector.parse(ifc_file, bpy.context.scene.BIMProperties.ifc_selector)
ifc_csv = ifccsv.IfcCsv()
ifc_csv.output = self.filepath
ifc_csv.attributes = [a.name for a in bpy.context.scene.BIMProperties.csv_attributes]
ifc_csv.export(ifc_selector_parser.file, ifc_selector_parser.results)
ifc_csv.selector = selector
ifc_csv.export(ifc_file, results)
return {'FINISHED'}