From 5a52f3aeea4b331ce8a991a8c681f668e180f63f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 7 Aug 2021 21:06:23 +1000 Subject: [PATCH] Fix #1528. Fix bug where IFC project libraries could not be imported as a file. --- src/blenderbim/blenderbim/bim/import_ifc.py | 16 ++++++++++++---- .../ifcopenshell/api/type/data.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index 603f7fc1ce..bd32c16cfd 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -349,7 +349,10 @@ class IfcImporter: props = bpy.context.scene.BIMGeoreferenceProperties if props.has_blender_offset: return - project = self.file.by_type("IfcProject")[0] + if self.file.schema == "IFC2X3": + project = self.file.by_type("IfcProject")[0] + else: + project = self.file.by_type("IfcContext")[0] site = self.find_decomposed_ifc_class(project, "IfcSite") if site and self.is_element_far_away(site[0], is_meters=False): return self.guess_georeferencing(site[0]) @@ -1004,8 +1007,13 @@ class IfcImporter: ) def create_project(self): - self.project = {"ifc": self.file.by_type("IfcProject")[0]} - self.project["blender"] = bpy.data.collections.new("IfcProject/{}".format(self.project["ifc"].Name)) + if self.file.schema == "IFC2X3": + self.project = {"ifc": self.file.by_type("IfcProject")[0]} + else: + self.project = {"ifc": self.file.by_type("IfcContext")[0]} + self.project["blender"] = bpy.data.collections.new( + "{}/{}".format(self.project["ifc"].is_a(), self.project["ifc"].Name) + ) obj = self.create_product(self.project["ifc"]) if obj: self.project["blender"].objects.link(obj) @@ -1140,7 +1148,7 @@ class IfcImporter: self.place_object_in_spatial_tree(self.file.by_id(ifc_definition_id), obj) def place_object_in_spatial_tree(self, element, obj): - if element.is_a("IfcProject"): + if element.is_a() in ["IfcProject", "IfcProjectLibrary"]: return elif element.is_a("IfcTypeObject"): self.type_collection.objects.link(obj) diff --git a/src/ifcopenshell-python/ifcopenshell/api/type/data.py b/src/ifcopenshell-python/ifcopenshell/api/type/data.py index c768bd6cf2..93eb65bffe 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/type/data.py +++ b/src/ifcopenshell-python/ifcopenshell/api/type/data.py @@ -23,10 +23,10 @@ class Data: product = cls.file.by_id(product_id) cls.types[product_id] = None if cls.file.schema == "IFC2X3": - if hasattr(product, "ObjectTypeOf"): + if getattr(product, "ObjectTypeOf", None): cls.types[product_id] = [o.id() for o in product.ObjectTypeOf[0].RelatedObjects] else: - if hasattr(product, "Types"): + if getattr(product, "Types", None): cls.types[product_id] = [o.id() for o in product.Types[0].RelatedObjects] @classmethod