blender/doc/python_api/examples/bpy.data.0.py
Campbell Barton 0640836baa PyDoc: number all examples to avoid conflicts when type checking
Examples were supported with/without number suffix,
this caused problems using mypy for type checking because it attempted
to resolve imports such as `mathutils` to the example file.

Having only some examples numbered already complicated documentation
for conventions with examples - simplify extraction and number all.
2026-02-12 00:51:02 +00:00

24 lines
558 B
Python

import bpy
# Print all objects.
for obj in bpy.data.objects:
print(obj.name)
# Print all scene names in a list.
print(bpy.data.scenes.keys())
# Remove mesh Cube.
if "Cube" in bpy.data.meshes:
mesh = bpy.data.meshes["Cube"]
print("removing mesh", mesh)
bpy.data.meshes.remove(mesh)
# Write images into a file next to the blend.
import os
with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w') as fs:
for image in bpy.data.images:
fs.write("{:s} {:d} x {:d}\n".format(image.filepath, image.size[0], image.size[1]))