Removing collections through the Blender Python API

We can delete collections in Blender through the “collections” list in “bpy.data”.

To remove a collection we need to use the “remove” method from the collections list, specifying the collection to be removed in the parameter:

When we delete a collection in this way, all objects from the collection will be unlinked from the scene, but will not be deleted as objects and remain in the blend-file.

To completely remove a collection and all objects in it, we must first delete the objects from the “objects” list, and then delete the collection itself.

This code removes the collection and all nested objects:

4.5 2 votes
Article Rating
Subscribe
Notify of
guest

4 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
aum
aum
4 months ago

should also remove all orphan data after deleting

Rombout Versluijs
Rombout
1 year ago

WHy is there no code for moving an collection?
I can seem to find any code for that, do you know ant perhaps