Removing objects from collections using Blender Python API

In Blender, any object can be removed from a collection, as well as from all collections to which this object has been added, using the Python API.

To remove the object from the collection with the desired name, we need to use the unlink() method on the objects list in this collection.

For example, let’s remove the currently active object from the collection named “Collection 2”:

To remove the active object from all collections, we need to loop through each collection and remove the object:

Please note that the unlink() command does not check for the existence of an object in the collection, so to avoid an error:

RuntimeError: Error: Object ‘Suzanne’ not in collection ‘Collection 2’

Before deleting, we need to check if the object exists in the collection.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments