Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

March 26, 2012

Deleting Objects from a scene

There might be quicker ways of doing this, but this describes the process.
# do not run this on a scene with more than 100 objects... it will be a waste of time. (printing is slow)
for item in bpy.data.objects:
... print(item.name, item.type)
... 

# objects of type mesh are containers for meshes.
# multiple differently named objects can share the same base mesh.
# objects are in that sense 'users' of mesh data.
for item in bpy.data.objects:
... if item.type == "MESH":
...     print(item.name)
... 
Mesh
Mesh.001

for mesh in bpy.data.meshes:
... print(mesh.name)
... 
Cube
Cube.001
Cube.002

# maybe use some blender forensics to consider the two printed sequences above. 
# what must I have done to have 3 mesh structures, but only 2 objects of type 'MESH'? 
we can't delete mesh data if an object uses it. And simply deleting an object doesn't flush the mesh it used (altho I do recall seeing a method that does exactly that) or if you can do a broad stroke: