From be262eaef27aa0965b7a342d53430fd0d1477aaa Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 1 May 2024 18:26:18 +0500 Subject: [PATCH] fix errors linking ifc2x3 projects it was failing with something very verbose: ``` File "\blenderbim\bim\module\project\operator.py", line 1239, in execute db = ifcpatch.execute( ^^^^^^^^^^^^^^^^^ File "\blenderbim\libs\site\packages\ifcpatch\__init__.py", line 80, in execute patcher.patch() File "\blenderbim\libs\site\packages\ifcpatch\recipes\ExtractPropertiesToSQLite.py", line 137, in patch properties.append([i, "IFC Material", f"Layer {idx + 1} Name", item.Name]) ^^^^^^^^^ File "\blenderbim\libs\site\packages\ifcopenshell\entity_instance.py", line 197, in __getattr__ raise AttributeError( AttributeError: entity instance of type 'IFC2X3.IfcMaterialLayer' has no attribute 'Name' Error: Python: Traceback (most recent call last): File "\blenderbim\bim\module\project\operator.py", line 1239, in execute db = ifcpatch.execute( ^^^^^^^^^^^^^^^^^ File "\blenderbim\libs\site\packages\ifcpatch\__init__.py", line 80, in execute patcher.patch() File "\blenderbim\libs\site\packages\ifcpatch\recipes\ExtractPropertiesToSQLite.py", line 137, in patch properties.append([i, "IFC Material", f"Layer {idx + 1} Name", item.Name]) ^^^^^^^^^ File "\blenderbim\libs\site\packages\ifcopenshell\entity_instance.py", line 197, in __getattr__ raise AttributeError( AttributeError: entity inTraceback (most recent call last): File "\Temp\tmpdggt3syt.py", line 9, in run() File "\Temp\tmpdggt3syt.py", line 5, in run bpy.ops.bim.load_linked_project(filepath="/Dormitory-ARC.ifc", false_origin="0,0,0") File "\Blender\4.1\scripts\modules\bpy\ops.py", line 109, in __call__ ret = _op_call(self.idname_py(), kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Error: Python: Traceback (most recent call last): File "\blenderbim\bim\module\project\operator.py", line 1239, in execute db = ifcpatch.execute( ^^^^^^^^^^^^^^^^^ File "\blenderbim\libs\site\packages\ifcpatch\__init__.py", line 80, in execute patcher.patch() File "\blenderbim\libs\site\packages\ifcpatch\recipes\ExtractPropertiesToSQLite.py", line 137, in patch properties.append([i, "IFC Material", f"Layer {idx + 1} Name", item.Name]) ^^^^^^^^^ File "\blenderbim\libs\site\packages\ifcopenshell\entity_instance.py", line 197, in __getattr__ raise AttributeError( AttributeError: entity instance of type 'IFC2X3.IfcMaterialLayer' has no attribute 'Name' Location: \Blender\4.1\scripts\modules\bpy\ops.py:109 ... truncatedUnregistered Snippets Library BMAX Connector - UnRegistred! An error occurred while processing your IFC. Traceback (most recent call last): File "\blenderbim\bim\module\project\operator.py", line 949, in execute self.link_ifc() File "\blenderbim\bim\module\project\operator.py", line 991, in link_ifc self.link_blend(blend_filepath) File "\blenderbim\bim\module\project\operator.py", line 953, in link_blend with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to): OSError: load: \Dormitory-ARC.ifc.cache.blend failed to open blend file Error: Python: Traceback (most recent call last): File "\blenderbim\bim\module\project\operator.py", line 949, in execute self.link_ifc() File "\blenderbim\bim\module\project\operator.py", line 991, in link_ifc self.link_blend(blend_filepath) File "\blenderbim\bim\module\project\operator.py", line 953, in link_blend with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to): OSError: load: \Dormitory-ARC.ifc.cache.blend failed to open blend file Location: \Blender\4.1\scripts\modules\bpy\ops.py:109 Traceback (most recent call last): File "\blenderbim\bim\module\project\operator.py", line 870, in execute bpy.ops.bim.load_link(filepath=filepath, false_origin=self.false_origin) File "\Blender\4.1\scripts\modules\bpy\ops.py", line 109, in __call__ ret = _op_call(self.idname_py(), kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Error: Python: Traceback (most recent call last): File "\blenderbim\bim\module\project\operator.py", line 949, in execute self.link_ifc() File "\blenderbim\bim\module\project\operator.py", line 991, in link_ifc self.link_blend(blend_filepath) File "\blenderbim\bim\module\project\operator.py", line 953, in link_blend with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to): OSError: load: \Dormitory-ARC.ifc.cache.blend failed to open blend file Location: \Blender\4.1\scripts\modules\bpy\ops.py:109 ``` --- .../recipes/ExtractPropertiesToSQLite.py | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/ifcpatch/ifcpatch/recipes/ExtractPropertiesToSQLite.py b/src/ifcpatch/ifcpatch/recipes/ExtractPropertiesToSQLite.py index f4c1761879..3b7f49de9c 100644 --- a/src/ifcpatch/ifcpatch/recipes/ExtractPropertiesToSQLite.py +++ b/src/ifcpatch/ifcpatch/recipes/ExtractPropertiesToSQLite.py @@ -23,6 +23,7 @@ import json import time import tempfile import ifcopenshell +import ifcopenshell.util.element try: import sqlite3 @@ -106,14 +107,16 @@ class Patcher: relationships = [] id_map = {e.id(): i for i, e in enumerate(elements)} for i, element in enumerate(elements): - rows.append([ - i, - element[0], - element.is_a(), - ifcopenshell.util.element.get_predefined_type(element), - element[2], - element[3], - ]) + rows.append( + [ + i, + element[0], # IfcRoot.GlobalId + element.is_a(), + ifcopenshell.util.element.get_predefined_type(element), + element[2], # IfcRoot.Name + element[3], # IfcRoot.Description + ] + ) psets = ifcopenshell.util.element.get_psets(element, should_inherit=False) for pset_name, pset_data in psets.items(): for prop_name, value in pset_data.items(): @@ -134,27 +137,30 @@ class Patcher: materials = [] elif material.is_a("IfcMaterialLayerSet"): for idx, item in enumerate(material.MaterialLayers): - properties.append([i, "IFC Material", f"Layer {idx + 1} Name", item.Name]) - properties.append([i, "IFC Material", f"Layer {idx + 1} Material", item.Material.Name]) - if getattr(item.Material, "Category"): - properties.append([i, "IFC Material", f"Layer {idx + 1} Category", item.Material.Category]) + material = item.Material + properties.append([i, "IFC Material", f"Layer {idx + 1} Name", getattr(item, "Name", None)]) + properties.append([i, "IFC Material", f"Layer {idx + 1} Material", material.Name]) + if category := getattr(material, "Category", None): + properties.append([i, "IFC Material", f"Layer {idx + 1} Category", category]) elif material.is_a("IfcMaterialProfileSet"): for idx, item in enumerate(material.MaterialProfiles): + material = item.Material properties.append([i, "IFC Material", f"Profile {idx + 1} Name", item.Name]) - properties.append([i, "IFC Material", f"Profile {idx + 1} Material", item.Material.Name]) - if getattr(item.Material, "Category"): - properties.append([i, "IFC Material", f"Profile {idx + 1} Category", item.Material.Category]) + properties.append([i, "IFC Material", f"Profile {idx + 1} Material", material.Name]) + if category := getattr(material, "Category", None): + properties.append([i, "IFC Material", f"Profile {idx + 1} Category", category]) elif material.is_a("IfcMaterialConstituentSet"): for idx, item in enumerate(material.MaterialConstituents): + material = item.Material properties.append([i, "IFC Material", f"Constituent {idx + 1} Name", item.Name]) - properties.append([i, "IFC Material", f"Constituent {idx + 1} Material", item.Material.Name]) - if getattr(item.Material, "Category"): - properties.append([i, "IFC Material", f"Constituent {idx + 1} Category", item.Material.Category]) + properties.append([i, "IFC Material", f"Constituent {idx + 1} Material", material.Name]) + if category := getattr(material, "Category", None): + properties.append([i, "IFC Material", f"Constituent {idx + 1} Category", category]) elif material.is_a("IfcMaterialList"): for idx, material in enumerate(material.Materials): properties.append([i, "IFC Material", f"Material {idx + 1} Name", material.Name]) - if getattr(material, "Category"): - properties.append([i, "IFC Material", f"Material {idx + 1} Category", material.Category]) + if category := getattr(material, "Category", None): + properties.append([i, "IFC Material", f"Material {idx + 1} Category", category]) layers = ifcopenshell.util.element.get_layers(self.file, element) for idx, layer in enumerate(layers):