From d71e34f07318c4eda0025bf7b255c4993135e44a Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 20 Mar 2023 19:42:54 +1100 Subject: [PATCH] Fix bug where 2D types were not loaded as a fallback from the body representation. --- src/blenderbim/blenderbim/bim/import_ifc.py | 32 +++++++++------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index b728c39e64..6b3c6ca0e2 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -625,37 +625,33 @@ class IfcImporter: def create_element_type(self, element): self.ifc_import_settings.logger.info("Creating object %s", element) - representation_map = self.get_type_product_body_representation_map(element) + representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") + if not representation: + representation = ifcopenshell.util.representation.get_representation(element, "Plan", "Annotation") + if not representation: + representation = ifcopenshell.util.representation.get_representation(element, "Model", "Annotation") mesh = None - if representation_map: - representation = representation_map.MappedRepresentation + if representation: mesh_name = "{}/{}".format(representation.ContextOfItems.id(), representation.id()) mesh = self.meshes.get(mesh_name) if mesh is None: + shape = None try: - shape = ifcopenshell.geom.create_shape(self.settings, representation_map.MappedRepresentation) + shape = ifcopenshell.geom.create_shape(self.settings, representation) + except: + try: + shape = ifcopenshell.geom.create_shape(self.settings_2d, representation) + except: + self.ifc_import_settings.logger.error("Failed to generate shape for %s", element) + if shape: mesh = self.create_mesh(element, shape) tool.Loader.link_mesh(shape, mesh) self.meshes[mesh_name] = mesh - except: - self.ifc_import_settings.logger.error("Failed to generate shape for %s", element) obj = bpy.data.objects.new(tool.Loader.get_name(element), mesh) self.link_element(element, obj) self.material_creator.create(element, obj, mesh) self.type_products[element.GlobalId] = obj - def get_type_product_body_representation_map(self, element): - if not element.RepresentationMaps: - return - for representation_map in element.RepresentationMaps: - context = representation_map.MappedRepresentation.ContextOfItems - if ( - context.ContextType == "Model" - and context.ContextIdentifier == "Body" - and context.TargetView == "MODEL_VIEW" - ): - return representation_map - def create_native_elements(self): progress = 0 checkpoint = time.time()