5

How to check if a collection is selected or not in the outliner using Python?

enter image description here

Here I've selected the following collections: "scene 1", "scene 2" and "scene 3".

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
Korchiy
  • 179
  • 8
  • very good question! there's no direct blender python api for that i guess. you can only know what the currently selected collection name is with bpy.context.collection.name – Harry McKenzie Jan 15 '23 at 09:49

1 Answers1

0

As far as I know, there is no direct way to check if certain collections are selected. You can only check what the name of the currently selected collection is using:

bpy.context.collection.name

and you can check what the actively selected collection is:

import bpy

for collection in bpy.data.collections: if collection == bpy.context.view_layer.active_layer_collection.collection: print(collection.name)

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51