Accessing Blender data
All the entities created in the current session are available as part of bpy.data
. They are grouped in categories that follow the object types available in Blender, so we have bpy.data.armatures
, bpy.data.curves
, and so on. Each category is a bpy_collection
, a Blender type that contains more elements. Their content can be accessed with indices, like in a Python list
, or with keywords, like in dictionaries.
Objects access
We can use Python to access the objects of a scene. For example, we can query the content of Blender’s default scene, which contains a Cube, a Camera and a Light:
- Open or restart Blender and select Scripting Workspace in the workspace tabs at the top of the screen.
Figure 2.10: The workspace tabs
- Type
len(bpy.data.objects)
and press Enter:>>> len(bpy.data.objects)
3
- In the Python console, type
bpy.data.objects
, then press Tab.
Figure 2.11: Blender...