from 2.7 to 2.8
How to link a new object to a scene in Blender 2.80 Python API
In Blender 2.79 Python API we can add a new object to a scene with:
1 |
bpy.context.scene.objects.link(new_object) |
If we try to do this in Blender 2.80, it throws an error:
‘bpy_prop_collection’ object has no attribute ‘link’
In Blender 2.80 API new objects mast be linked not to the scene, but to the scene collections:
To link a new object to the active scene collection:
1 |
bpy.context.scene.collection.objects.link(new_object) |
To link a new object to the collection by its name:
1 |
bpy.data.collections['collection_name'].objects.link(new_object) |
15 changes that you need to know when migrating from Blender 2.79 to Blender 2.80
- Object selection
2.79: selecting with the right mouse button
2.80: left-click selection
- T-panel
2.79: called by pressing the “t” key
2.80: it’s gone, functions moved to the main menu and to the context right-click menu
- Deselection
2.79: “a” – select all and deselect all
2.80: “a” – select all, “a – a” or “alt+a” – deselect all
15 changes that you need to know when migrating from Blender 2.79 to Blender 2.80Read More »
Class naming conventions in Blender 2.8 Python API
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:
1 |
UPPER_CASE_{SEPARATOR}_mixed_case |
Where the {SEPARATOR} is two letters denoting the class belonging to a certain type (from which type the class is inherited):
- HT – Header
- MT – Menu
- OT – Operator
- PT – Panel
- UL – UI list
The class identifier “bl_idname” mast match the class name.
Class naming conventions in Blender 2.8 Python APIRead More »
Changes in add-ons registration through the API in Blender 2.8
Add-on registration and removing were made with the “Window manager” (wm) in Blender 2.7 Python API:
1 2 3 4 5 |
bpy.ops.wm.addon_install(filepath='_path_to_addon', overwrite=True) bpy.ops.wm.addon_enable(module='addon_name') bpy.ops.wm.addon_remove(module='addon_name') |
In Blender 2.8 API add-on operators moved to the “preferences”:
1 2 3 4 5 |
bpy.ops.preferences.addon_install(filepath='_path_to_addon', overwrite=True) bpy.ops.preferences.addon_enable(module='addon_name') bpy.ops.preferences.addon_remove(module='addon_name') |
3D Cursor location in Blender 2.8 Python API
3D-cursor location property
1 |
context.scene.cursor_location |
in Blender 2.8 API moved to “cursor” object
1 |
context.scene.cursor.location |
When trying to get the cursor location through the “context.scene.cursor_location” Blender throws an error:
‘Scene’ object has no attribute ‘cursor_location’
Matrix, vector and quaternion multiplication in Blender 2.8 Python API
In Blender 2.7 the “*” (star) operator is used in the matrix, vector, and quaternion multiplication. In Blender 2.8 it is replaced with the “@” (at) operator.
If the “*” operator is used in vector, matrix or quaternion multiplication in Blender 2.8 it throws an error:
Element-wise multiplication: not supported between ‘Matrix’ and ‘Matrix’ types
Proper use of the “@” operator:
1 |
bpy.context.region_data.view_rotation @ Vector((0.0, 0.0, 1.0)) |
Snapping elements property in Blender 2.8 Python API
The snapping elements property from Blender 2.7
1 |
bpy.context.scene.tool_settings.snap_element |
changed in Blender 2.8 API to
1 2 |
bpy.context.scene.tool_settings.snap_elements # {'EDGE'} |
Accessing the pivot point type in Blender 2.8 Python API
The “pivot_point” property from Blender 2.7
1 2 |
bpy.context.area.spaces[0].pivot_point # 'BOUNDING_BOX_CENTER': |
in Blender 2.8 API moved to:
1 2 |
bpy.context.scene.tool_settings.transform_pivot_point # 'MEDIAN_POINT' |
use_drag_immediately property in Blender 2.8 Python API
The “use_drag_immediately” property from Blender 2.7
1 |
bpy.context.preferences.edit.use_drag_immediately |
in Blender 2.8 API moved to
1 2 |
bpy.context.preferences.inputs.use_drag_immediately # True |