Paste Code
Paste Blends
Paste Images
# orphan_slayer.py (c) 2011 Phil Cote (cotejrp1)
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****

bl_info = {
'name': 'Orphan Slayer',
'author': 'Phil Cote, cotejrp1, (http://www.blenderaddons.com)',
'version': (0,1),
"blender": (2, 5, 9),
"api": 35853,
'location': 'VIEW 3D -> TOOLS',
'description': 'Deletes objects from a scene and from the bpy.data modules',
'warning': '', # used for warning icon and text in addons panel
'category': 'System'}

import bpy, random, time
from pdb import set_trace


class DeleteSceneObsOp(bpy.types.Operator):
'''.'''
bl_idname = "ba.delete_scene_obs"
bl_label = "Delete Scene Objects"

def execute(self, context):
for ob in context.scene.objects:
context.scene.objects.unlink(ob)
return {'FINISHED'}


class DeleteOrphansOp(bpy.types.Operator):

bl_idname="ba.delete_data_obs"
bl_label="Delete Orphans"

def execute(self, context):
target_coll = eval("bpy.data." + context.scene.mod_list)
print("chosen target collection: " + str(target_coll))
print( "size of target collection: %d" % len(target_coll) )
for item in target_coll:
if item.users == 0:
target_coll.remove(item)

return {'FINISHED'}


class OrphanSlayerPanel( bpy.types.Panel ):

bl_label = "Orphan Slayer"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"

def draw( self, context ):
scn = context.scene

layout = self.layout
col = layout.column()
layout.column().prop(scn, "mod_list")
col.operator("ba.delete_scene_obs")
col.operator("ba.delete_data_obs")


def register():

mod_data = [tuple(["actions"]*3), tuple(["armatures"]*3),
tuple(["cameras"]*3), tuple(["curves"]*3),
tuple(["fonts"]*3), tuple(["grease_pencil"]*3),
tuple(["groups"]*3), tuple(["images"]*3),
tuple(["lamps"]*3), tuple(["lattices"]*3),
tuple(["libraries"]*3), tuple(["materials"]*3),
tuple(["meshes"]*3), tuple(["metaballs"]*3),
tuple(["node_groups"]*3), tuple(["objects"]*3),
tuple(["sounds"]*3), tuple(["texts"]*3),
tuple(["textures"]*3),]


bpy.types.Scene.mod_list = bpy.props.EnumProperty(name="Orphan Target",
items=mod_data,
description="Module choice made for orphan deletion")
bpy.utils.register_class(DeleteSceneObsOp)
bpy.utils.register_class(DeleteOrphansOp)
bpy.utils.register_class(OrphanSlayerPanel)


def unregister():
bpy.utils.unregister_class(DeleteSceneObsOp)
bpy.utils.unregister_class(DeleteOrphansOp)
bpy.utils.unregister_class(OrphanSlayerPanel)


if __name__ == "__main__":
register()
  1. # orphan_slayer.py (c) 2011 Phil Cote (cotejrp1)
  2. #
  3. # ***** BEGIN GPL LICENSE BLOCK *****
  4. #
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #
  20. # ***** END GPL LICENCE BLOCK *****
  21.  
  22. bl_info = {
  23.     'name': 'Orphan Slayer',
  24.     'author': 'Phil Cote, cotejrp1, (http://www.blenderaddons.com)',
  25.     'version': (0,1),
  26.     "blender": (2, 5, 9),
  27.     "api": 35853,
  28.     'location': 'VIEW 3D -> TOOLS',
  29.     'description': 'Deletes objects from a scene and from the bpy.data modules',
  30.     'warning': '', # used for warning icon and text in addons panel
  31.     'category': 'System'}
  32.  
  33. import bpy, random, time
  34. from pdb import set_trace
  35.  
  36.    
  37. class DeleteSceneObsOp(bpy.types.Operator):
  38.     '''.'''
  39.     bl_idname = "ba.delete_scene_obs"
  40.     bl_label = "Delete Scene Objects"
  41.  
  42.     def execute(self, context):
  43.         for ob in context.scene.objects:
  44.             context.scene.objects.unlink(ob)
  45.         return {'FINISHED'}
  46.  
  47.  
  48. class DeleteOrphansOp(bpy.types.Operator):
  49.    
  50.     bl_idname="ba.delete_data_obs"
  51.     bl_label="Delete Orphans"
  52.    
  53.     def execute(self, context):
  54.         target_coll = eval("bpy.data." + context.scene.mod_list)
  55.         print("chosen target collection: " + str(target_coll))
  56.         print( "size of target collection: %d" % len(target_coll) )
  57.         for item in target_coll:
  58.             if item.users == 0:
  59.                 target_coll.remove(item)
  60.        
  61.         return {'FINISHED'}
  62.    
  63.  
  64. class OrphanSlayerPanel( bpy.types.Panel ):
  65.    
  66.     bl_label = "Orphan Slayer"
  67.     bl_space_type = "VIEW_3D"
  68.     bl_region_type = "TOOLS"
  69.     bl_context = "objectmode"
  70.    
  71.     def draw( self, context ):
  72.         scn = context.scene
  73.        
  74.         layout = self.layout
  75.         col = layout.column()
  76.         layout.column().prop(scn, "mod_list")
  77.         col.operator("ba.delete_scene_obs")
  78.         col.operator("ba.delete_data_obs")
  79.    
  80.  
  81. def register():
  82.  
  83.     mod_data = [tuple(["actions"]*3), tuple(["armatures"]*3),
  84.                  tuple(["cameras"]*3), tuple(["curves"]*3),
  85.                  tuple(["fonts"]*3), tuple(["grease_pencil"]*3),
  86.                  tuple(["groups"]*3), tuple(["images"]*3),
  87.                  tuple(["lamps"]*3), tuple(["lattices"]*3),
  88.                  tuple(["libraries"]*3), tuple(["materials"]*3),
  89.                  tuple(["meshes"]*3), tuple(["metaballs"]*3),
  90.                  tuple(["node_groups"]*3), tuple(["objects"]*3),
  91.                  tuple(["sounds"]*3), tuple(["texts"]*3),
  92.                  tuple(["textures"]*3),]
  93.    
  94.    
  95.     bpy.types.Scene.mod_list = bpy.props.EnumProperty(name="Orphan Target",
  96.                                                         items=mod_data,
  97.                                                         description="Module choice made for orphan deletion")
  98.     bpy.utils.register_class(DeleteSceneObsOp)
  99.     bpy.utils.register_class(DeleteOrphansOp)
  100.     bpy.utils.register_class(OrphanSlayerPanel)
  101.    
  102.  
  103. def unregister():
  104.     bpy.utils.unregister_class(DeleteSceneObsOp)
  105.     bpy.utils.unregister_class(DeleteOrphansOp)
  106.     bpy.utils.unregister_class(OrphanSlayerPanel)
  107.  
  108.  
  109. if __name__ == "__main__":
  110.     register()
go to heaven