To set mesh (object) as active in Blender 2.8 Python API the “context.view_layer” is used instead of “context.scene”.
When trying to make object active with “bpy.context.scene.objects.active” Blender throws an error:
AttributeError: bpy_prop_collection: attribute “active” not found
To make object active in Blender 2.8 use the following code:
1 2 |
obj = bpy.context.window.scene.objects[0] bpy.context.view_layer.objects.active = obj # 'obj' is the active object now |