Results 1 to 8 of 8
  1. #1

    delete object from all scenes

    I've been looking for ways to remove objects from all scenes at once but haven't found any so I've written a small add-on that takes care of the job. The script can be installed like any other add-on. Once activated it adds a panel (containing one button) to the toolshelf; pressing the button will remove all selected objects from all scenes.

    Ideally I'd like the button to appear in the Object Tools panel instead of in its own panel. Also it would be neat to assign a shortcut (for example alt-x or shift-x) to the function; any hints regarding those improvements will be appreciated.

    Code:
    import bpy
    
    bl_info = {
        "name": "Delete From All Scenes",
        "description": "This will delete an object from all scenes rather than just from the current one.",
        "author": "Abel",
        "version": (0,1),
        "blender": (2, 5, 9),
        "api": 40791,
        "location": "Object Tools > Delete From All Scenes panel > Delete from all scenes",
        "warning": "", # used for warning icon and text in addons panel
        "category": "Object"}
    
    ## interface ##
    
    class DeleteFromAllScenesPanel(bpy.types.Panel) :
        bl_space_type = "VIEW_3D"
        bl_region_type = "TOOLS"
        bl_context = "objectmode"
        bl_label = "Delete From All Scenes"
    
        def draw(self, context) :
            TheCol = self.layout.column(align = True)
            TheCol.operator("object.delete_from_all_scenes", text = "Delete From All Scenes")
    # end interface class
    
    ## operator ##
    
    class DeleteFromAllScenes(bpy.types.Operator):
        bl_idname = "object.delete_from_all_scenes"
        bl_label = "Delete Object From All Scenes"
        bl_options = {"UNDO"}
        
        ## actual function ## 
        def invoke(self, context, event):
            for i in range (0,len(bpy.context.selected_objects)):
                current_object = bpy.context.selected_objects[0]
                # unlink object from all scenes
                for sce in bpy.data.scenes:
                    try:    sce.objects.unlink(current_object)
                    except:    pass
            return {"FINISHED"}
        # end invoke
    # end operator class
    
    def register():
        bpy.utils.register_class(DeleteFromAllScenes)
        bpy.utils.register_class(DeleteFromAllScenesPanel)
    def unregister():
        bpy.utils.register_class(DeleteFromAllScenes)
        bpy.utils.register_class(DeleteFromAllScenesPanel)
    download link: http://www.everholt.org/abel/delete_from_all_scenes.py
    Last edited by abelabel; 10-Oct-11 at 13:55.



  2. #2
    Hi abelabel,

    this addon is very useful! Thanks for that!
    People on my ignore list: DcVertice, Love 3D



  3. #3
    Member Atom's Avatar
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    11,632
    Hmm...there does seem to be some flaws in your logic. From reading the code it will only delete objects in scenes that are selected in a given scene, correct? Is that the intention? Also unlinking is not the same a deleting.

    Here is how I would unlink and delete from memory all objects in the entire BLEND file.
    Code:
    import bpy
    
    for scene in bpy.data.scenes:
        for ob in scene.objects:
            scene.objects.unlink(ob)
            bpy.data.objects.remove(ob)
    Unlink and remove can fail and generate errors that you will need to trap for (as you have done in your above code) but this small code snippet is more inline with your original stated intention.



  4. #4
    Wow, I hadn't expected any replies on this after all this time. With recent versions of Blender, the delete command has a "Delete Globally" option which does what I wanted to do, so the script should no longer be necessary.

    @Atom: thanks for the comments! I wasn't aware of the .remove functionality, I'll make sure to use it if I need to remove objects through a script again. As to only deleting selected objects, that is intentional although I can see my intention being ambiguous from the way I formulated it in my original message.



  5. #5
    Originally Posted by abelabel View Post
    Wow, I hadn't expected any replies on this after all this time. With recent versions of Blender, the delete command has a "Delete Globally" option which does what I wanted to do, so the script should no longer be necessary.
    Yep, I already noticed that, but when I searched on the google, I first found your addon . I also didn't check how old this thread is...
    People on my ignore list: DcVertice, Love 3D



  6. #6
    Member McBuff's Avatar
    Join Date
    Nov 2011
    Location
    Hoogstraten, Belgium
    Posts
    464
    Yup, and the hotkey is Shift+X ( very handy )
    "Put Smarties tubes on cats legs make them walk like a robot"
    -Jimmy Carr



  7. #7
    Any way to delete globally a material? Meaning delete from all objects using that material.



  8. #8
    Hay friend,
    I am also having the same problem. Please give some suggestion and ways about to delete the materials. If you are having any idea to dot this. I am waiting for you suggestion. What is the best way for removing the objects from screen?



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •