link new object to scene with python in 2.8 In Python 2.8, I would like to create copies of the object 'CubeTemplate' but am having no luck.  I have reviewed every blender.stackexchange post on this subject (this, this, this and this) but cannot get them to work - either they don't apply or the sample code throws errors (perhaps because it was pre 2.8).

The code below throws this error:  


  AttributeError: 'bpy_prop_collection' object has no attribute 'link'


for x in range(1, 3):
    bpy.data.objects['CubeTemplate'].select_set(True)
    bpy.context.view_layer.objects.active = bpy.data.objects['CubeTemplate']
    me = bpy.context.object.data # use current object's data
    me_copy = me.copy()
    ob = bpy.data.objects.new('CubeCopy'+str(x), me_copy)
    ob.location = (0, 0, x)
    scene = bpy.context.scene
    scene.objects.link(ob)
    scene.update()
The issue with your code comes from an api change in 2.80.
We no longer link objects to the scene, they have to be linked to a collection.

So all you have to do to make your script work is to change your scene references to collections

You old code:

scene = bpy.context.scene
scene.objects.link(ob)
scene.update()


Replace with this:

scene = bpy.context.scene
scene.collection.objects.link(ob)


Or shorter:

bpy.context.collection.objects.link(ob)


Or if you wanted to link the objects to a specific collection you'd do this with this line:

bpy.data.collections["Collection Name"].objects.link(ob)