mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 06:32:09 +00:00
Add progress bar when importing. Fix #759.
This commit is contained in:
@@ -204,10 +204,16 @@ class IfcImporter():
|
|||||||
if not valid_file:
|
if not valid_file:
|
||||||
self.create_products_legacy() # Sometimes, this can still work, not 100% sure why yet
|
self.create_products_legacy() # Sometimes, this can still work, not 100% sure why yet
|
||||||
return False
|
return False
|
||||||
|
old_progress = -1
|
||||||
while True:
|
while True:
|
||||||
|
progress = iterator.progress() // 2
|
||||||
|
if progress > old_progress:
|
||||||
|
print("\r[" + "#" * progress + " " * (50 - progress) + "]", end="")
|
||||||
|
old_progress = progress
|
||||||
self.create_product(iterator.get())
|
self.create_product(iterator.get())
|
||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
break
|
break
|
||||||
|
print("\rDone creating geometry" + " " * 30)
|
||||||
|
|
||||||
def create_product(self, shape):
|
def create_product(self, shape):
|
||||||
if shape is None:
|
if shape is None:
|
||||||
@@ -215,7 +221,7 @@ class IfcImporter():
|
|||||||
|
|
||||||
element = self.file.by_id(shape.guid)
|
element = self.file.by_id(shape.guid)
|
||||||
|
|
||||||
print('Creating object {}'.format(element))
|
self.ifc_import_settings.logger.info('Creating object {}'.format(element))
|
||||||
|
|
||||||
# TODO: make names more meaningful
|
# TODO: make names more meaningful
|
||||||
mesh_name = f'mesh-{shape.geometry.id}'
|
mesh_name = f'mesh-{shape.geometry.id}'
|
||||||
@@ -247,7 +253,7 @@ class IfcImporter():
|
|||||||
self.diff = json.load(file)
|
self.diff = json.load(file)
|
||||||
|
|
||||||
def load_file(self):
|
def load_file(self):
|
||||||
print('loading file {}'.format(self.ifc_import_settings.input_file))
|
self.ifc_import_settings.logger.info('loading file {}'.format(self.ifc_import_settings.input_file))
|
||||||
self.file = ifcopenshell.open(self.ifc_import_settings.input_file)
|
self.file = ifcopenshell.open(self.ifc_import_settings.input_file)
|
||||||
|
|
||||||
def calculate_unit_scale(self):
|
def calculate_unit_scale(self):
|
||||||
@@ -337,7 +343,7 @@ class IfcImporter():
|
|||||||
and element.GlobalId not in self.diff['changed'].keys():
|
and element.GlobalId not in self.diff['changed'].keys():
|
||||||
return
|
return
|
||||||
|
|
||||||
print('Creating object {}'.format(element))
|
self.ifc_import_settings.logger.info('Creating object {}'.format(element))
|
||||||
self.time = time.time()
|
self.time = time.time()
|
||||||
if element.is_a('IfcOpeningElement'):
|
if element.is_a('IfcOpeningElement'):
|
||||||
return
|
return
|
||||||
@@ -350,16 +356,16 @@ class IfcImporter():
|
|||||||
if mesh is None \
|
if mesh is None \
|
||||||
or representation_id is None:
|
or representation_id is None:
|
||||||
shape = ifcopenshell.geom.create_shape(self.settings, element)
|
shape = ifcopenshell.geom.create_shape(self.settings, element)
|
||||||
print('Shape was generated in {:.2f}'.format(time.time() - self.time))
|
self.ifc_import_settings.logger.info('Shape was generated in {:.2f}'.format(time.time() - self.time))
|
||||||
self.time = time.time()
|
self.time = time.time()
|
||||||
|
|
||||||
mesh = self.create_mesh(element, shape)
|
mesh = self.create_mesh(element, shape)
|
||||||
self.meshes[mesh_name] = mesh
|
self.meshes[mesh_name] = mesh
|
||||||
self.mesh_shapes[mesh_name] = shape
|
self.mesh_shapes[mesh_name] = shape
|
||||||
else:
|
else:
|
||||||
print('MESH REUSED')
|
self.ifc_import_settings.logger.info('Mesh reused.')
|
||||||
except:
|
except:
|
||||||
print('Failed to generate shape for {}'.format(element))
|
self.ifc_import_settings.logger.error('Failed to generate shape for {}'.format(element))
|
||||||
return
|
return
|
||||||
|
|
||||||
obj = bpy.data.objects.new(self.get_name(element), mesh)
|
obj = bpy.data.objects.new(self.get_name(element), mesh)
|
||||||
@@ -395,7 +401,7 @@ class IfcImporter():
|
|||||||
and element.HasFillings:
|
and element.HasFillings:
|
||||||
bpy.data.collections.get('IfcOpeningElements').objects.link(obj)
|
bpy.data.collections.get('IfcOpeningElements').objects.link(obj)
|
||||||
else:
|
else:
|
||||||
print('Warning: this object is outside the spatial hierarchy')
|
self.ifc_import_settings.logger.warning('Warning: this object is outside the spatial hierarchy')
|
||||||
bpy.context.scene.collection.objects.link(obj)
|
bpy.context.scene.collection.objects.link(obj)
|
||||||
|
|
||||||
def add_element_attributes(self, element, obj):
|
def add_element_attributes(self, element, obj):
|
||||||
@@ -483,8 +489,7 @@ class IfcImporter():
|
|||||||
mesh.from_pydata(vertices, edges, faces)
|
mesh.from_pydata(vertices, edges, faces)
|
||||||
return mesh
|
return mesh
|
||||||
except:
|
except:
|
||||||
print('Could not create mesh for {}: {}/{}'.format(
|
self.ifc_import_settings.logger.error('Could not create mesh for {}: {}/{}'.format(element.GlobalId, self.get_name(element)))
|
||||||
element.GlobalId, self.get_name(element)))
|
|
||||||
|
|
||||||
def a2p(self, o, z, x):
|
def a2p(self, o, z, x):
|
||||||
y = z.cross(x)
|
y = z.cross(x)
|
||||||
|
|||||||
Reference in New Issue
Block a user