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...

Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

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:

July 03, 2011

Deleting a face from a mesh

if you are modifying data of an object, sometimes you want to remove a face
# must be in edit mode.

# first select the face, then delete it.
mplane.data.faces[-1].select = True # won't show in viewport
bpy.ops.mesh.delete(type='ONLY_FACE') # will be acted on.
must be in edit mode for these options, other options for types are found by reading the tooltips in the delete menu.