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
Blender Api Reference
To make object active in Blender 2.8 use the following code:
Blender uses the Python programming language for its scripting API. The Blender Python API is based on Python 3. It is integrated deeply, used for writing add-ons, generating user interface layouts, and import and export of many file formats. It covers all user-accessible data and functionality. Blender Open Data is a platform to collect, display and query the results of hardware and software performance tests - provided by the public. In Blender 2.8 API the requirements for the class and their identifiers naming are becoming tougher. The class name must match the following convention. To completely remove the object from the scene through the Blender Python API do the following: Open the “Text Editor” window. Import the main Blender Python API module. Welcome to the Python API documentation for Blender, the free and open source 3D creation suite. This site can be used offline: Download the full documentation (zipped HTML files).
Blender Api Key
Blender Api
2 | bpy.context.view_layer.objects.active=obj# 'obj' is the active object now |