[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37099] branches/soc-2011-pepper/release/ scripts/startup/bl_operators/nla.py: Added operator to remove all useless unused actions from the current

Joshua Leung aligorith at gmail.com
Thu Jun 2 15:03:47 CEST 2011


Revision: 37099
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37099
Author:   aligorith
Date:     2011-06-02 13:03:46 +0000 (Thu, 02 Jun 2011)
Log Message:
-----------
Added operator to remove all useless unused actions from the current
.blend file.
* From operator search, find "Clear Useless Actions"
* "Action library" actions are preserved by this operator. It targets
actions without any F-Curves
* By default, only actions which are single-user (where that user is a
Fake user) will be targeted. This can be changed to have it target any
"dangling" action that doesn't have any F-Curves
* A save/reload cycle is still required to fully remove such Actions
from the current file. Though at least now it's a simpler process to
have these semi-automatically removed ;)

Modified Paths:
--------------
    branches/soc-2011-pepper/release/scripts/startup/bl_operators/nla.py

Modified: branches/soc-2011-pepper/release/scripts/startup/bl_operators/nla.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/bl_operators/nla.py	2011-06-02 12:44:59 UTC (rev 37098)
+++ branches/soc-2011-pepper/release/scripts/startup/bl_operators/nla.py	2011-06-02 13:03:46 UTC (rev 37099)
@@ -168,3 +168,37 @@
     def invoke(self, context, event):
         wm = context.window_manager
         return wm.invoke_props_dialog(self)
+        
+#################################
+
+class ClearUselessActions(bpy.types.Operator):
+    '''Mark actions with no F-Curves for deletion after save+reload of file preserving "action libraries"'''
+    bl_idname = "anim.clear_useless_actions"
+    bl_label = "Clear Useless Actions"
+    bl_options = {'REGISTER', 'UNDO'}
+    
+    only_unused = BoolProperty(name="Only Unused", 
+            description="Only unused (Fake User only) actions get considered",
+            default=True)
+    
+    @classmethod
+    def poll(cls, context):
+        return len(bpy.data.actions) != 0
+        
+    def execute(self, context):
+        removed = 0
+        
+        for action in bpy.data.actions:
+            # if only user is "fake" user...
+            if ((self.only_unused is False) or 
+                (action.use_fake_user and action.users == 1)):
+                
+                # if it has F-Curves, then it's a "action library" (i.e. walk, wave, jump, etc.) 
+                # and should be left alone as that's what fake users are for!
+                if not action.fcurves:
+                    # mark action for deletion
+                    action.user_clear()
+                    removed += 1
+        
+        self.report({'INFO'}, "Removed %d empty and/or fake-user only Actions" % (removed))
+        return {'FINISHED'}




More information about the Bf-blender-cvs mailing list