I would like to select the top Collection (called "Scene Collection") from my script. If I test any other collection in the scene in the console with:


I get something like: bpy.data.collections['Collection']

But if the top "Scene Collection" is active, I get: bpy.data.scenes['Scene'].collection

Therefore a code like this:

collections = bpy.context.view_layer.layer_collection.children
for collection in collections:
    if collection.name == "Scene":
        bpy.context.view_layer.active_layer_collection = collection

don't work as this top collection is not among the "normal" collections.

Is there a way to select it out of a script? (To make sure that anything new created out of the script will originate under this top collection and not inside some other collection which were created previously from the script.)


1 Answer 1


It seems you answered yourself. To get the Scene collection, use bpy.data.scenes[...].collection or bpy.context.view_layer.layer_collection if you're after the current main collection. You already do this in your code. You're not going to have the main collection within the children of the main collection, therefore the check you want to perform will always yield False.

If you have a list of collections obtained in another way, consider comparing a collection with the main collection like so:

if some_collection == bpy.context.view_layer.layer_collection:
    # ...
  • $\begingroup$ Thanks! Not seeing the forest from a tree. =) $\endgroup$
    – Steve
    Jun 7, 2023 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .