From dd3fc79fb949c868265fe4cf09030dbda1fa0903 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 14 Oct 2021 15:53:25 +1100 Subject: [PATCH] Use context filters during import when possible to optimise import times --- src/blenderbim/blenderbim/bim/import_ifc.py | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index e28f28a8c6..5866ccc992 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -207,6 +207,8 @@ class IfcImporter: self.profile_code("Create project") self.process_element_filter() self.profile_code("Process element filter") + self.process_context_filter() + self.profile_code("Process context filter") self.create_collections() self.profile_code("Create collections") self.create_openings_collection() @@ -266,6 +268,25 @@ class IfcImporter: coords = point.Coordinates return abs(coords[0]) > limit or abs(coords[1]) > limit or abs(coords[2]) > limit + def process_context_filter(self): + # Facetation is to accommodate broken Revit files + # See https://forums.buildingsmart.org/t/suggestions-on-how-to-improve-clarity-of-representation-context-usage-in-documentation/3663/6?u=moult + self.body_contexts = [ + c.id() + for c in self.file.by_type("IfcGeometricRepresentationSubContext") + if c.ContextIdentifier in ["Body", "Facetation"] + ] + if self.body_contexts: + self.settings.set_context_ids(self.body_contexts) + self.non_body_contexts = [ + c.id() + for c in self.file.by_type("IfcGeometricRepresentationSubContext") + if c.ContextIdentifier not in ["Body", "Facetation"] + ] + if self.non_body_contexts: + self.settings_2d.set_context_ids(self.non_body_contexts) + + def process_element_filter(self): if self.ifc_import_settings.has_filter: self.elements = set(self.ifc_import_settings.elements) @@ -605,14 +626,16 @@ class IfcImporter: shape = iterator.get() if shape: product = self.file.by_id(shape.guid) - # Facetation is to accommodate broken Revit files - # See https://forums.buildingsmart.org/t/suggestions-on-how-to-improve-clarity-of-representation-context-usage-in-documentation/3663/6?u=moult - if shape.context not in ["Body", "Facetation"] and IfcStore.get_element(shape.guid): - # We only load a single context, and we prioritise the Body context. See #1290. - pass - else: + if self.body_contexts: self.create_product(product, shape) results.add(product) + else: + if shape.context not in ["Body", "Facetation"] and IfcStore.get_element(shape.guid): + # We only load a single context, and we prioritise the Body context. See #1290. + pass + else: + self.create_product(product, shape) + results.add(product) if not iterator.next(): break print("Done creating geometry")