mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 02:31:09 +00:00
Support for exporting IFCZIP files. See #834
This commit is contained in:
@@ -139,11 +139,11 @@ if bpy is not None:
|
|||||||
|
|
||||||
def menu_func_export(self, context):
|
def menu_func_export(self, context):
|
||||||
self.layout.operator(operator.ExportIFC.bl_idname,
|
self.layout.operator(operator.ExportIFC.bl_idname,
|
||||||
text="Industry Foundation Classes (.ifc)")
|
text="Industry Foundation Classes (.ifc/.ifczip)")
|
||||||
|
|
||||||
def menu_func_import(self, context):
|
def menu_func_import(self, context):
|
||||||
self.layout.operator(operator.ImportIFC.bl_idname,
|
self.layout.operator(operator.ImportIFC.bl_idname,
|
||||||
text="Industry Foundation Classes (.ifc)")
|
text="Industry Foundation Classes (.ifc/.ifczip)")
|
||||||
|
|
||||||
def on_register(scene):
|
def on_register(scene):
|
||||||
prop.setDefaultProperties(scene)
|
prop.setDefaultProperties(scene)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import json
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import zipfile
|
||||||
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from mathutils import Vector, Matrix
|
from mathutils import Vector, Matrix
|
||||||
from .helper import SIUnitHelper
|
from .helper import SIUnitHelper
|
||||||
@@ -1146,7 +1148,7 @@ class IfcExporter():
|
|||||||
self.relate_to_objectives(self.ifc_parser.rel_associates_constraint_objective_type)
|
self.relate_to_objectives(self.ifc_parser.rel_associates_constraint_objective_type)
|
||||||
self.relate_structural_members_to_connections()
|
self.relate_structural_members_to_connections()
|
||||||
self.relate_objects_to_groups()
|
self.relate_objects_to_groups()
|
||||||
self.file.write(self.ifc_export_settings.output_file)
|
self.write_ifc_file()
|
||||||
|
|
||||||
def set_common_definitions(self):
|
def set_common_definitions(self):
|
||||||
# Owner history doesn't actually work like this, but for now, it does :)
|
# Owner history doesn't actually work like this, but for now, it does :)
|
||||||
@@ -2422,6 +2424,20 @@ class IfcExporter():
|
|||||||
def convert_si_to_unit(self, co):
|
def convert_si_to_unit(self, co):
|
||||||
return co / self.ifc_parser.unit_scale
|
return co / self.ifc_parser.unit_scale
|
||||||
|
|
||||||
|
def write_ifc_file(self):
|
||||||
|
extension = self.ifc_export_settings.output_file.split('.')[-1]
|
||||||
|
if extension == 'ifczip':
|
||||||
|
with tempfile.TemporaryDirectory() as unzipped_path:
|
||||||
|
filename, ext = os.path.splitext(os.path.basename(self.ifc_export_settings.output_file))
|
||||||
|
tmp_name = '{}.ifc'.format(filename)
|
||||||
|
tmp_file = os.path.join(unzipped_path, tmp_name)
|
||||||
|
self.file.write(tmp_file)
|
||||||
|
with zipfile.ZipFile(self.ifc_export_settings.output_file,
|
||||||
|
mode='w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
|
||||||
|
zf.write(tmp_file)
|
||||||
|
elif extension == 'ifc':
|
||||||
|
self.file.write(self.ifc_export_settings.output_file)
|
||||||
|
|
||||||
|
|
||||||
class IfcExportSettings:
|
class IfcExportSettings:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ colour_list = [
|
|||||||
|
|
||||||
class ExportIFC(bpy.types.Operator):
|
class ExportIFC(bpy.types.Operator):
|
||||||
bl_idname = "export.ifc"
|
bl_idname = "export.ifc"
|
||||||
bl_label = "Export .ifc file"
|
bl_label = "Export IFC"
|
||||||
filename_ext = ".ifc"
|
filename_ext = ".ifc"
|
||||||
filepath: bpy.props.StringProperty(subtype='FILE_PATH')
|
filepath: bpy.props.StringProperty(subtype='FILE_PATH')
|
||||||
|
|
||||||
@@ -51,7 +51,11 @@ class ExportIFC(bpy.types.Operator):
|
|||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename=context.scene.BIMProperties.data_dir + 'process.log',
|
filename=context.scene.BIMProperties.data_dir + 'process.log',
|
||||||
filemode='a', level=logging.DEBUG)
|
filemode='a', level=logging.DEBUG)
|
||||||
output_file = bpy.path.ensure_ext(self.filepath, '.ifc')
|
extension = self.filepath.split('.')[-1]
|
||||||
|
if extension == 'ifczip':
|
||||||
|
output_file = bpy.path.ensure_ext(self.filepath, '.ifczip')
|
||||||
|
else:
|
||||||
|
output_file = bpy.path.ensure_ext(self.filepath, '.ifc')
|
||||||
ifc_export_settings = export_ifc.IfcExportSettings.factory(context, output_file, logger)
|
ifc_export_settings = export_ifc.IfcExportSettings.factory(context, output_file, logger)
|
||||||
ifc_parser = export_ifc.IfcParser(ifc_export_settings)
|
ifc_parser = export_ifc.IfcParser(ifc_export_settings)
|
||||||
qto_calculator = export_ifc.QtoCalculator()
|
qto_calculator = export_ifc.QtoCalculator()
|
||||||
@@ -63,7 +67,7 @@ class ExportIFC(bpy.types.Operator):
|
|||||||
|
|
||||||
class ImportIFC(bpy.types.Operator, ImportHelper):
|
class ImportIFC(bpy.types.Operator, ImportHelper):
|
||||||
bl_idname = "import.ifc"
|
bl_idname = "import.ifc"
|
||||||
bl_label = "Import .ifc file"
|
bl_label = "Import IFC"
|
||||||
filename_ext = ".ifc"
|
filename_ext = ".ifc"
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip", options={'HIDDEN'})
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip", options={'HIDDEN'})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user