IfcZip and IfcXML can now be set manually, and prevent double loading when importing, which can save ~20 seconds for large file imports.

This commit is contained in:
Dion Moult
2021-08-21 16:16:53 +10:00
parent 3b36029b1d
commit fd603f7035
3 changed files with 19 additions and 24 deletions
+1 -2
View File
@@ -153,8 +153,7 @@ def purge_module_data():
def loadIfcStore(scene):
IfcStore.purge()
purge_module_data()
ifc_file = IfcStore.get_file()
if not ifc_file:
if not IfcStore.get_file():
return
IfcStore.get_schema()
IfcStore.reload_linked_elements()
+17 -2
View File
@@ -60,11 +60,26 @@ class IfcStore:
IfcStore.path = bpy.context.scene.BIMProperties.ifc_file
if IfcStore.path:
try:
IfcStore.file = ifcopenshell.open(IfcStore.path)
IfcStore.load_file(IfcStore.path)
except:
IfcStore.file
pass
return IfcStore.file
@staticmethod
def load_file(path):
extension = path.split(".")[-1]
if extension.lower() == "ifczip":
with tempfile.TemporaryDirectory() as unzipped_path:
with zipfile.ZipFile(path, "r") as zip_ref:
zip_ref.extractall(unzipped_path)
for filename in Path(unzipped_path).glob("**/*.ifc"):
IfcStore.file = ifcopenshell.open(filename)
return
elif extension.lower() == "ifcxml":
IfcStore.file = ifcopenshell.file(ifcopenshell.ifcopenshell_wrapper.parse_ifcxml(path))
elif extension.lower() == "ifc":
IfcStore.file = ifcopenshell.open(path)
@staticmethod
def get_schema():
if IfcStore.file is None:
+1 -20
View File
@@ -214,8 +214,6 @@ class IfcImporter:
self.profile_code("Purge diffs")
self.load_file()
self.profile_code("Loading file")
self.set_ifc_file()
self.profile_code("Setting file")
self.calculate_unit_scale()
self.profile_code("Calculate unit scale")
self.calculate_model_offset()
@@ -973,25 +971,8 @@ class IfcImporter:
def load_file(self):
self.ifc_import_settings.logger.info("loading file %s", self.ifc_import_settings.input_file)
extension = self.ifc_import_settings.input_file.split(".")[-1]
if extension.lower() == "ifczip":
with tempfile.TemporaryDirectory() as unzipped_path:
with zipfile.ZipFile(self.ifc_import_settings.input_file, "r") as zip_ref:
zip_ref.extractall(unzipped_path)
for filename in Path(unzipped_path).glob("**/*.ifc"):
self.file = ifcopenshell.open(filename)
break
elif extension.lower() == "ifcxml":
self.file = ifcopenshell.file(
ifcopenshell.ifcopenshell_wrapper.parse_ifcxml(self.ifc_import_settings.input_file)
)
elif extension.lower() == "ifc":
self.file = ifcopenshell.open(self.ifc_import_settings.input_file)
IfcStore.file = self.file
def set_ifc_file(self):
bpy.context.scene.BIMProperties.ifc_file = self.ifc_import_settings.input_file
IfcStore.path = self.ifc_import_settings.input_file
self.file = IfcStore.get_file()
def calculate_unit_scale(self):
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)