I got this script working which will collapse all collections in the View Layer

def toggle_collection_collapse():
    area = next(a for a in bpy.context.screen.areas if a.type == 'OUTLINER')
    with bpy.context.temp_override(**bpy.context.copy()):
        bpy.ops.outliner.show_hierarchy({'area': area}, 'INVOKE_DEFAULT')
        bpy.ops.outliner.expanded_toggle({'area': area})
        bpy.ops.outliner.expanded_toggle({'area': area})

Now what I will like is to collapse collections that are not excluded with the checkbox

enter image description here

So for example the collection trees should be collapsed but the flowers collection not

I looked at the blender API and I can't find how to just collapse a single collection, only all of them at the same time.

I am missing something?

  • 1
    $\begingroup$ As far as I know there is no way to specify which collection to collapse or expand. $\endgroup$ Oct 20, 2023 at 8:06


You must log in to answer this question.

Browse other questions tagged .