diff --git a/core/common.py b/core/common.py index 01673b6..e3a9067 100644 --- a/core/common.py +++ b/core/common.py @@ -653,6 +653,9 @@ def store_breaking_settings_armature(armature: bpy.types.Object) -> ArmatureData return (armature_data.use_mirror_x, armature.pose.use_mirror_x) def restore_breaking_settings_armature(armature: bpy.types.Object, data: ArmatureData) -> None: + # Check if armature object is still valid (not removed) + if not armature or armature.name not in bpy.data.objects: + return armature_data: bpy.types.Armature = armature.data armature_data.use_mirror_x, armature.pose.use_mirror_x = data diff --git a/functions/custom_tools/armature_merging.py b/functions/custom_tools/armature_merging.py index 69fbd73..0a73586 100644 --- a/functions/custom_tools/armature_merging.py +++ b/functions/custom_tools/armature_merging.py @@ -48,6 +48,9 @@ class AvatarToolkit_OT_MergeArmature(bpy.types.Operator): #Store current armature settings that can mess us up. data_breaking_base = store_breaking_settings_armature(base_armature) data_breaking_merge = store_breaking_settings_armature(merge_armature) + + # Store the merge armature name before it gets removed during join + merge_armature_name_stored = merge_armature.name # Remove Rigid Bodies and Joints delete_rigidbodies_and_joints(base_armature) @@ -77,14 +80,17 @@ class AvatarToolkit_OT_MergeArmature(bpy.types.Operator): wm.progress_end() restore_breaking_settings_armature(base_armature, data_breaking_base) - restore_breaking_settings_armature(merge_armature, data_breaking_merge) + + if merge_armature_name_stored in bpy.data.objects: + merge_armature_obj = bpy.data.objects[merge_armature_name_stored] + restore_breaking_settings_armature(merge_armature_obj, data_breaking_merge) self.report({'INFO'}, t('MergeArmature.success')) return {'FINISHED'} except Exception as e: - logger.error(f"Error merging armatures:", exception=e) + logger.error(f"Error merging armatures: {str(e)}\n{traceback.format_exc()}") self.report({'ERROR'}, traceback.format_exc()) return {'CANCELLED'}