To set mesh (object) as active in Blender 2.8 Python API the “context.view_layer” is used instead of “context.scene”.
The Blender Python API is an unparalleled programmable visualization environment. Using the API is made difficult due to its complex object hierarchy and vast documentation. Understanding the Blender Python API clearly explains the interface. You will become familiar with data structures and low-level concepts in both modeling and rendering. I use unittest.mock for replace dependencies like Blender API. I use VSCode Editor for writing Python scripts.
When trying to make object active with “bpy.context.scene.objects.active” Blender throws an error:
Blender Api 2.7
Blender Api Deselect All
AttributeError: bpy_prop_collection: attribute “active” not found
To make object active in Blender 2.8 use the following code:
bpy.context.view_layer.objects.active=obj# 'obj' is the active object now