Create Blender export plugin

This commit is contained in:
Dion Moult
2019-09-26 21:55:30 +10:00
parent a41e7fc298
commit 1f371f3319
12 changed files with 78 additions and 15 deletions
@@ -0,0 +1,71 @@
bl_info = {
"name": "IfcBlenderExport",
"description": "Export files in the "
"Industry Foundation Classes (.ifc) file format",
"author": "Dion Moult, IfcOpenShell",
"blender": (2, 80, 0),
"location": "File > Export",
"tracker_url": "https://sourceforge.net/p/ifcopenshell/"
"_list/tickets?source=navbar",
"category": "Import-Export"}
if "bpy" in locals():
from importlib import reload
reload(export)
del reload
import bpy
import time
from . import export
import os
from bpy.props import (StringProperty,)
cwd = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
class ExportIFC(bpy.types.Operator):
bl_idname = "export.ifc"
bl_label = "Export .ifc file"
filename_ext = ".ifc"
#filter_glob: StringProperty(default="*.ifc", options={'HIDDEN'})
filepath: StringProperty(subtype='FILE_PATH')
def invoke(self, context, event):
if not self.filepath:
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".ifc")
WindowManager = context.window_manager
WindowManager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self, context):
print('# Starting export')
start = time.time()
ifc_export_settings = export.IfcExportSettings()
ifc_export_settings.bim_path = cwd
ifc_export_settings.output_file = bpy.path.ensure_ext(self.filepath, '.ifc')
ifc_parser = export.IfcParser(ifc_export_settings)
ifc_schema = export.IfcSchema(ifc_export_settings)
qto_calculator = export.QtoCalculator()
ifc_exporter = export.IfcExporter(ifc_export_settings, ifc_schema, ifc_parser, qto_calculator)
ifc_exporter.export()
print('# Export finished in {:.2f} seconds'.format(time.time() - start))
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(ExportIFC.bl_idname,
text="Industry Foundation Classes (.ifc)")
classes = (ExportIFC,)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_file_export.append(menu_func)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
bpy.types.TOPBAR_MT_file_export.remove(menu_func)
if __name__ == "__main__":
register()
@@ -63,8 +63,8 @@ class QtoCalculator():
return volume
class IfcSchema():
def __init__(self):
self.schema_dir = '/home/dion/Projects/IfcOpenShell/src/ifcblenderexport/schema/'
def __init__(self, ifc_export_settings):
self.schema_dir = '{}schema/'.format(ifc_export_settings.bim_path)
self.property_file = ifcopenshell.open(self.schema_dir + 'IFC4_ADD2.ifc')
self.psets = {}
self.qtos = {}
@@ -84,7 +84,7 @@ class IfcSchema():
class IfcParser():
def __init__(self, ifc_export_settings):
self.data_dir = '/home/dion/Projects/IfcOpenShell/src/ifcblenderexport/data/'
self.data_dir = '{}data/'.format(ifc_export_settings.bim_path)
self.ifc_export_settings = ifc_export_settings
@@ -672,8 +672,8 @@ class SIUnitHelper:
class IfcExporter():
def __init__(self, ifc_export_settings, ifc_schema, ifc_parser, qto_calculator):
self.template_file = '/home/dion/Projects/IfcOpenShell/src/ifcblenderexport/template.ifc'
self.output_file = '/home/dion/Projects/IfcOpenShell/src/ifcblenderexport/output.ifc'
self.template_file = '{}template.ifc'.format(ifc_export_settings.bim_path)
self.output_file = ifc_export_settings.output_file
self.ifc_export_settings = ifc_export_settings
self.ifc_schema = ifc_schema
self.ifc_parser = ifc_parser
@@ -1245,17 +1245,9 @@ class IfcExporter():
class IfcExportSettings:
def __init__(self):
self.bim_path = None
self.output_file = None
self.has_representations = True
self.has_quantities = True
self.subcontexts = ['Axis', 'FootPrint', 'Reference', 'Body', 'Clearance', 'CoG']
self.generated_subcontexts = ['Box']
print('# Starting export')
start = time.time()
ifc_export_settings = IfcExportSettings()
ifc_parser = IfcParser(ifc_export_settings)
ifc_schema = IfcSchema()
qto_calculator = QtoCalculator()
ifc_exporter = IfcExporter(ifc_export_settings, ifc_schema, ifc_parser, qto_calculator)
ifc_exporter.export()
print('# Export finished in {:.2f} seconds'.format(time.time() - start))