To have the access to the current context, for example, to work with operators, and to the scene data, for example, to work with meshes, we use two predefined structures from the Blender Python API: “bpy.context” and “bpy.data”.
For example, we can pass them to a function:
1 2 3 4 5 6 7 8 9 10 11 |
import bpy def my_func(context, scene_data): print(context, scene_data) my_func( context=bpy.context, scene_data=bpy.data ) # <bpy_struct, Context at 0x00000000050EF568> <bpy_struct, BlendData at 0x0000000007FA6408> |
However, in the “bpy.context” structure there is a “blend_data” pointer that links to the scene data. With this pointer, we can access scene data without passing it separately and explicitly.
1 2 3 4 5 6 7 8 9 10 |
import bpy def my_func(context): print(context, context.blend_data) my_func( context=bpy.context, ) # <bpy_struct, Context at 0x00000000050EF568> <bpy_struct, BlendData at 0x0000000007FA6408> |