From 744ed522b64c4b2558d4fe507f4c92d0a472400f Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 6 May 2025 11:51:38 +0500 Subject: [PATCH] Fix error duplicating just an IfcElementAssembly (d2b05ea) Example error traceback: ``` Traceback (most recent call last): File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\geometry\operator.py", line 1044, in execute return OverrideDuplicateMove.execute_duplicate_operator(self, context, linked=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\geometry\operator.py", line 1055, in execute_duplicate_operator IfcStore.execute_ifc_operator(operator, context) File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\bim\ifc.py", line 458, in execute_ifc_operator result = getattr(operator, "_execute")(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\geometry\operator.py", line 1047, in _execute return OverrideDuplicateMove.execute_ifc_duplicate_operator(self, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\geometry\operator.py", line 1085, in execute_ifc_duplicate_operator old_to_new, new_active_obj = tool.Geometry.duplicate_ifc_objects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\tool\geometry.py", line 2131, in duplicate_ifc_objects tool.Root.recreate_aggregate(old_to_new) File "C:\Users\Andrej\AppData\Roaming\Blender Foundation\Blender\4.4\extensions\.local\lib\python3.11\site-packages\bonsai\tool\root.py", line 397, in recreate_aggregate tool.Blender.select_and_activate_single_object(bpy.context, tool.Ifc.get_object(new_aggregate[0])) ~~~~~~~~~~~~~^^^ TypeError: 'NoneType' object is not subscriptable ``` --- src/bonsai/bonsai/tool/root.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bonsai/bonsai/tool/root.py b/src/bonsai/bonsai/tool/root.py index 1c6a1f4312..ee50f6804b 100644 --- a/src/bonsai/bonsai/tool/root.py +++ b/src/bonsai/bonsai/tool/root.py @@ -357,6 +357,7 @@ class Root(bonsai.core.tool.Root): def recreate_aggregate( cls, old_to_new: dict[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance]] ) -> None: + new_aggregate = None for old, new in old_to_new.items(): old_aggregate = ifcopenshell.util.element.get_aggregate(old) if old_aggregate: @@ -393,6 +394,8 @@ class Root(bonsai.core.tool.Root): related_obj=tool.Ifc.get_object(tool.Ifc.get_entity(obj)), ) + if new_aggregate is None: + return tool.Blender.select_and_activate_single_object(bpy.context, tool.Ifc.get_object(new_aggregate[0])) @classmethod