From cfc243949dec797f7a7510fa25a30f734941a6cd Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 6 Sep 2024 12:36:14 +0500 Subject: [PATCH] Fix error unassigning type from element without representation Traceback Traceback (most recent call last): File "\bonsai\bim\module\type\operator.py", line 63, in execute return IfcStore.execute_ifc_operator(self, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\bonsai\bim\ifc.py", line 408, in execute_ifc_operator result = getattr(operator, "_execute")(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\bonsai\bim\module\type\operator.py", line 78, in _execute active_context = active_representation.ContextOfItems ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'ContextOfItems' Error: Python: Traceback (most recent call last): File "\bonsai\bim\ifc.py", line 408, in execute_ifc_operator result = getattr(operator, "_execute")(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\bonsai\bim\module\type\operator.py", line 78, in _execute active_context = active_representation.ContextOfItems ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'ContextOfItems' --- src/bonsai/bonsai/bim/module/type/operator.py | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/type/operator.py b/src/bonsai/bonsai/bim/module/type/operator.py index b072f0fd67..31db2fdd98 100644 --- a/src/bonsai/bonsai/bim/module/type/operator.py +++ b/src/bonsai/bonsai/bim/module/type/operator.py @@ -74,11 +74,10 @@ class UnassignType(bpy.types.Operator): continue ifcopenshell.api.run("type.unassign_type", self.file, related_objects=[element]) - active_representation = tool.Geometry.get_active_representation(obj) - active_context = active_representation.ContextOfItems - new_active_representation = None - if element.Representation: + new_active_representation = None + active_representation = tool.Geometry.get_active_representation(obj) + active_context = active_representation.ContextOfItems representations = [] for representation in element.Representation.Representations: resolved_representation = ifcopenshell.util.representation.resolve_representation(representation) @@ -97,16 +96,16 @@ class UnassignType(bpy.types.Operator): new_active_representation = copied_representation element.Representation.Representations = representations - if new_active_representation: - bonsai.core.geometry.switch_representation( - tool.Ifc, - tool.Geometry, - obj=obj, - representation=new_active_representation, - should_reload=False, - is_global=False, - should_sync_changes_first=False, - ) + if new_active_representation: + bonsai.core.geometry.switch_representation( + tool.Ifc, + tool.Geometry, + obj=obj, + representation=new_active_representation, + should_reload=False, + is_global=False, + should_sync_changes_first=False, + ) return {"FINISHED"}