Merge with trunk r37677
[blender.git] / release / scripts / startup / bl_operators / nla.py
index 7cbdaa3..a895916 100644 (file)
@@ -253,3 +253,37 @@ class BakeAction(bpy.types.Operator):
     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'}