From 482cb539acc2ade5fab93a197f7b9f5640348b51 Mon Sep 17 00:00:00 2001 From: georgeto Date: Sat, 9 Mar 2024 22:47:31 +0100 Subject: [PATCH] Improve error when importing animation without actor selected --- g3blend/util.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/g3blend/util.py b/g3blend/util.py index 33baa8e..b7c2b7d 100644 --- a/g3blend/util.py +++ b/g3blend/util.py @@ -86,10 +86,14 @@ def similar_values_iter(v1, v2, epsilon=1e-6): def find_armature(context: bpy.types.Context) -> Optional[bpy.types.Object]: # TODO: Find actor by name or at least check compatibility? actor_obj = context.active_object - arm_obj = next((c for c in actor_obj.children if c.type == 'ARMATURE'), None) - if arm_obj is None and actor_obj.parent: - arm_obj = next((c for c in actor_obj.parent.children if c.type == 'ARMATURE'), None) - return arm_obj + if actor_obj is None: + return None + + if arm_obj := next((c for c in actor_obj.children if c.type == 'ARMATURE'), None): + return arm_obj + + if actor_obj.parent: + return next((c for c in actor_obj.parent.children if c.type == 'ARMATURE'), None) # Note: Taken from KrxImpExp