Blender Python API : How to select a collection in the Outliner?

Viewed 385

I am trying to select a collection in blender by name. I was successful to find the collection in the outliner and make it an active collection using the following code

def recurLayerCollection(layerColl, collName):
        found = None
        if (layerColl.name == collName):
            return layerColl
        for layer in layerColl.children:
            found = recurLayerCollection(layer, collName)
            if found:
                return found
    
    layer_collection = bpy.context.view_layer.layer_collection
    layerColl = recurLayerCollection(layer_collection, 'Set')
    bpy.context.view_layer.active_layer_collection = layerColl

This highlights the collection I am looking for but does not actually select it, as shown in the picture.

Outliner Screenshot

As you can see, it highlighted the collection "Set", but it does not select it. How can I select it? I could not find anything in the API that can help. I will be grateful for any help or suggestion.

0 Answers
Related