This is a quick reference guide on how to delete all objects in a scene using Blender Python.
Introduction
When working with Blender Python through trial and error, you may want to delete all objects in the scene. This is a quick reference on how to do that with a Python script.
# Working Version Blender 4.2.0
Note: This article was translated from my original post.
Deleting All Existing Objects in Blender Python
This Python script will delete all existing objects in the scene:
import bpy bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete()
The process is straightforward:
- Switch to Object Mode
- Select all objects
- Delete the selected objects
Ideally, following best practices for the Blender Python API, you'd want to use the bpy.data API instead of the bpy.ops API for more flexible operations. However, if you simply want to delete all objects in the scene, the straightforward code shown above is sufficient.
Conclusion
That's a quick reference on how to delete all existing objects in Blender Python.
Manual GUI operations lack reproducibility and can't be automated, but by keeping Python scripts on hand, you can eliminate small frustrations.
I hope this helps someone out there.
[Related Articles]