From b83c1181425040f1e10d0826bb8e218ed8ee938a Mon Sep 17 00:00:00 2001
From: Bastien Montagne <montagne29@wanadoo.fr>
Date: Thu, 20 Nov 2014 19:44:17 +0100
Subject: [PATCH] FBX Import: Long time request/todo: assign first read action
 to object automatically.

This does by no mean handle complex setups, but most common basic situations
should be read correctly, and it's much more user-friendly!
---
 io_scene_fbx/import_fbx.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index fdf6b9b57..d821672dd 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -587,7 +587,8 @@ def blen_read_animations_action_item(action, item, cnodes, fps):
 def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene):
     """
     Recreate an action per stack/layer/object combinations.
-    Note actions are not linked to objects, this is up to the user!
+    Only the first found action is linked to objects, more complex setups are not handled,
+    it's up to user to reproduce them!
     """
     from bpy.types import ShapeKey
 
@@ -603,12 +604,19 @@ def blen_read_animations(fbx_tmpl_astack, fbx_tmpl_alayer, stacks, scene):
                     id_data = item.bl_obj
                 if id_data is None:
                     continue
+                # Create new action if needed (should always be needed!
                 key = (as_uuid, al_uuid, id_data)
                 action = actions.get(key)
                 if action is None:
                     action_name = "|".join((id_data.name, stack_name, layer_name))
                     actions[key] = action = bpy.data.actions.new(action_name)
                     action.use_fake_user = True
+                # If none yet assigned, assign this action to id_data.
+                if not id_data.animation_data:
+                    id_data.animation_data_create()
+                if not id_data.animation_data.action:
+                    id_data.animation_data.action = action
+                # And actually populate the action!
                 blen_read_animations_action_item(action, item, cnodes, scene.render.fps)
 
 
-- 
GitLab