[Bf-blender-cvs] [a4a59d578cc] master: PyAPI: Add object argument to bake_action

Campbell Barton noreply at git.blender.org
Sun Sep 10 06:22:25 CEST 2017


Commit: a4a59d578cc835477c90e9e5920edaead61fb644
Author: Campbell Barton
Date:   Sun Sep 10 14:30:03 2017 +1000
Branches: master
https://developer.blender.org/rBa4a59d578cc835477c90e9e5920edaead61fb644

PyAPI: Add object argument to bake_action

Avoids having to set the scene's active object first.

===================================================================

M	release/scripts/modules/bpy_extras/anim_utils.py
M	release/scripts/startup/bl_operators/anim.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/anim_utils.py b/release/scripts/modules/bpy_extras/anim_utils.py
index 5e21260e5e4..ee270c6e8c7 100644
--- a/release/scripts/modules/bpy_extras/anim_utils.py
+++ b/release/scripts/modules/bpy_extras/anim_utils.py
@@ -26,23 +26,27 @@ import bpy
 
 
 # XXX visual keying is actually always considered as True in this code...
-def bake_action(frame_start,
-                frame_end,
-                frame_step=1,
-                only_selected=False,
-                do_pose=True,
-                do_object=True,
-                do_visual_keying=True,
-                do_constraint_clear=False,
-                do_parents_clear=False,
-                do_clean=False,
-                action=None,
-                ):
+def bake_action(
+        obj,
+        frame_start,
+        frame_end,
+        frame_step=1,
+        only_selected=False,
+        do_pose=True,
+        do_object=True,
+        do_visual_keying=True,
+        do_constraint_clear=False,
+        do_parents_clear=False,
+        do_clean=False,
+        action=None,
+):
 
     """
     Return an image from the file path with options to search multiple paths
     and return a placeholder if its not found.
 
+    :arg obj: Object to bake.
+    :type obj: :class:`bpy.types.Object`
     :arg frame_start: First frame to bake.
     :type frame_start: int
     :arg frame_end: Last frame to bake.
@@ -114,7 +118,6 @@ def bake_action(frame_start,
 
     # TODO, pass data rather then grabbing from the context!
     scene = bpy.context.scene
-    obj = bpy.context.object
     frame_back = scene.frame_current
 
     if obj.pose is None:
diff --git a/release/scripts/startup/bl_operators/anim.py b/release/scripts/startup/bl_operators/anim.py
index a843c17217a..380c1257a3d 100644
--- a/release/scripts/startup/bl_operators/anim.py
+++ b/release/scripts/startup/bl_operators/anim.py
@@ -258,27 +258,28 @@ class BakeAction(Operator):
             )
 
     def execute(self, context):
-
         from bpy_extras import anim_utils
 
+        obj = context.object
         action = None
         if self.use_current_action:
-            obj = context.object
             if obj.animation_data:
                 action = obj.animation_data.action
 
-        action = anim_utils.bake_action(self.frame_start,
-                                        self.frame_end,
-                                        frame_step=self.step,
-                                        only_selected=self.only_selected,
-                                        do_pose='POSE' in self.bake_types,
-                                        do_object='OBJECT' in self.bake_types,
-                                        do_visual_keying=self.visual_keying,
-                                        do_constraint_clear=self.clear_constraints,
-                                        do_parents_clear=self.clear_parents,
-                                        do_clean=True,
-                                        action=action,
-                                        )
+        action = anim_utils.bake_action(
+            obj,
+            self.frame_start,
+            self.frame_end,
+            frame_step=self.step,
+            only_selected=self.only_selected,
+            do_pose='POSE' in self.bake_types,
+            do_object='OBJECT' in self.bake_types,
+            do_visual_keying=self.visual_keying,
+            do_constraint_clear=self.clear_constraints,
+            do_parents_clear=self.clear_parents,
+            do_clean=True,
+            action=action,
+        )
 
         if action is None:
             self.report({'INFO'}, "Nothing to bake")



More information about the Bf-blender-cvs mailing list