Specifying an IFC diff now does an incremental import

This commit is contained in:
Dion Moult
2019-11-18 10:18:21 +11:00
parent 5237f4a634
commit c46167073b
2 changed files with 27 additions and 0 deletions
@@ -68,6 +68,7 @@ class MaterialCreator():
class IfcImporter():
def __init__(self, ifc_import_settings):
self.ifc_import_settings = ifc_import_settings
self.diff = None
self.file = None
self.settings = ifcopenshell.geom.settings()
if self.ifc_import_settings.should_import_curves:
@@ -83,14 +84,22 @@ class IfcImporter():
self.material_creator = MaterialCreator()
def execute(self):
self.load_diff()
self.load_file()
self.calculate_unit_scale()
self.create_project()
self.create_spatial_hierarchy()
self.purge_diff()
elements = self.file.by_type('IfcElement') + self.file.by_type('IfcSpace')
for element in elements:
self.create_object(element)
def load_diff(self):
if not self.ifc_import_settings.diff_file:
return
with open(self.ifc_import_settings.diff_file, 'r') as file:
self.diff = json.load(file)
def load_file(self):
print('loading file {}'.format(self.ifc_import_settings.input_file))
self.file = ifcopenshell.open(self.ifc_import_settings.input_file)
@@ -140,7 +149,23 @@ class IfcImporter():
def get_name(self, element):
return '{}/{}'.format(element.is_a(), element.Name)
def purge_diff(self):
objects_to_purge = []
for obj in bpy.data.objects:
if 'GlobalId' not in obj.BIMObjectProperties.attributes:
continue
global_id = obj.BIMObjectProperties.attributes['GlobalId'].string_value
if global_id in self.diff['deleted'] \
or global_id in self.diff['changed'].keys():
objects_to_purge.append(obj)
bpy.ops.object.delete({'selected_objects': objects_to_purge})
def create_object(self, element):
if self.diff:
if element.GlobalId not in self.diff['added'] \
and element.GlobalId not in self.diff['changed'].keys():
return
print('Creating object {}'.format(element))
self.time = time.time()
if element.is_a('IfcOpeningElement'):
@@ -305,3 +330,4 @@ class IfcImportSettings:
self.input_file = None
self.should_ignore_site_coordinates = False
self.should_import_curves = False
self.diff_file = None
@@ -59,6 +59,7 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
ifc_import_settings.logger = logging.getLogger('ImportIFC')
ifc_import_settings.logger.info('Starting import')
ifc_import_settings.input_file = self.filepath
ifc_import_settings.diff_file = bpy.context.scene.BIMProperties.diff_json_file
ifc_import_settings.should_ignore_site_coordinates = bpy.context.scene.BIMProperties.import_should_ignore_site_coordinates
ifc_import_settings.should_import_curves = bpy.context.scene.BIMProperties.import_should_import_curves
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)