Checking Mesh Validity?

Hey Everyone,
I’m writing a simple operator and noticed that if I delete the default Cube from the scene, and add a Sphere, both the cube and sphere appear in the mesh collection. Here’s my code:

    for me in
            print('!! '

Has anyone got any ideas why ‘Cube’ is listed as a mesh when I’ve deleted it, and how I can (properly?) iterate through the meshes to only meshes that are valid (and seen) in my scene?


Deleted objects are not removed from the “working” blend file - how else would you “undo”? You will have to look at the object details to know if it is “visible” or not :slight_smile:

you could just check if the mesh has any user -as in the script- or just save and reload
and regarding undo I don’t see my deleted words in a text editor, or deleted stuff in other 3d software…
this can be a nice feature but is not a standard

import bpy
meshes = [m for m in if m.users]
for a in meshes: print (a)

Thanks for the help guys, the code samples worked wonderfully.

Jambay: Out of the blue, rather than deleting the object outright from the mesh collection, any object that is deleted could be moved to a garbage collection pool which is deleted when the undo information is cleared. This would allow iteration over the mesh collection showing only valid mesh data, but you could still undo deleted objects if needed. Just a thought.

Thanks again for your help.

Is there a function to clear this data, other than reloading the file?

I like it!


liero had the answer right - “m.users” let’s you know if it’s “active, in use, present” for the scene. Being able to view deleted/unused items comes in handy with Blender, especially when selecting textures. Garbage collection is manual - close, restart :slight_smile: