以下の内容はhttps://en.bioerrorlog.work/entry/delete-all-objects-blender-pythonより取得しました。


Deleting All Existing Objects in Blender Python

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:

  1. Switch to Object Mode
  2. Select all objects
  3. 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]

en.bioerrorlog.work

References




以上の内容はhttps://en.bioerrorlog.work/entry/delete-all-objects-blender-pythonより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14