Link collection from external .blend in 2.8 via python I tried to recreate the File->Link...->somefile.blend->Collection->Collection linking mechanism in Blender 2.8 (Release canditate) in a script.

Unfortunatley my linking code does not behave like when I link via the GUI.

GUI:
-> I get an EMPTY that I can move/rotate/scale /duplicate etc. (orange collection Icon without a "link symbol"). A linked collection inside of it. Perfect! This is what I want.

SCRIPT:
-> I get a collection that is linked that I cant move etc. This behaviour seems not really usefull to me. I want to at least do the basic opperations on a "referenced"/linked object like move/rotate/scale.

I tried to place the linked collection in an EMPTY but the GUI does not allow that.

My script so far:

    context = bpy.context
    scenes = []
    mainCollection = bpy.data.collections['Collection']
    with bpy.data.libraries.load(blendFile) as (data_from, data_to):
        for name in data_from.scenes:
            scenes.append({'name': name})
        action = bpy.ops.wm.link
        action(directory=blendFile + "/Scene/", files=scenes)
        scenes = bpy.data.scenes[-len(scenes):]
    for scene in scenes:
        print(scene.name)
        for coll in scene.collection.children:
            print(coll.name)
            context.scene.collection.children.link(coll)


Any ideas how to place the linked collection inside an EMPTY via script to move it?

collection.parent = empty


A collection does not have a "parent" attribute.

Thanks in advance!
Thanks for your initial self-answer! It got me on the right track.

I think this way is even easier:

import bpy

master_collection = bpy.context.scene.collection

blendFile = 'path/to/file.blend'

with bpy.data.libraries.load(blendFile) as (data_from, data_to):
    data_to.collections = data_from.collections


for new_coll in data_to.collections:
    instance = bpy.data.objects.new(new_coll.name, None)
    instance.instance_type = 'COLLECTION'
    instance.instance_collection = new_coll
    master_collection.objects.link(instance)