Changed Linked Collection via Python

Hi there,

I would like to change a linked collection of many linked objects in a scene. Is there any way to do this via Python?

Consider this:
I have a collection inside an external file named “object_LOW” that is currently linked to the master file.
Now I would like the master file to use the collection “object_HIGH” of the linked file instead.
The linked file itself stays the same.

Any way to do this?

Thanks in advance!

yep, super easy- just loop through all of the instanced objects and change their instance_collection attribute


low_collection = bpy.data.collections['low_collection']
high_collection = bpy.data.collections['high_collection']

for o in bpy.data.objects:
    if o.instance_collection == low_collection:
        o.instance_collection = high_collection

Thanks testure!

Works like a charm! :slight_smile:

The only thing I recognized is that both collections must be in the master file so it can be switched to otherwise I cant get the reference to it:

low_collection = bpy.data.collections['low_collection']
high_collection = bpy.data.collections['high_collection']

It would be great to change the instance_collection by just a “String” value and if a collection with that name is not found in the instanced file it is just skipped or a null is shown.

That way one could add a new collection to the instanced file and switch to that too!

Other than that it does the job!