Cleanup: naming & reduce declaration scope in the PyAPI for lib loading

Use terms source/destination instead of from/to.
This commit is contained in:
Campbell Barton
2025-08-02 02:10:59 +00:00
parent 58c7bb3fc7
commit 6d899a6726
2 changed files with 42 additions and 49 deletions

View File

@@ -3,32 +3,32 @@ import bpy
filepath = "//link_library.blend"
# Load a single scene we know the name of.
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
with bpy.data.libraries.load(filepath) as (data_src, data_dst):
data_dst.scenes = ["Scene"]
# Load all meshes.
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.meshes = data_from.meshes
with bpy.data.libraries.load(filepath) as (data_src, data_dst):
data_dst.meshes = data_src.meshes
# Link all objects starting with "A".
with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
with bpy.data.libraries.load(filepath, link=True) as (data_src, data_dst):
data_dst.objects = [name for name in data_src.objects if name.startswith("A")]
# Append everything.
with bpy.data.libraries.load(filepath) as (data_from, data_to):
for attr in dir(data_to):
setattr(data_to, attr, getattr(data_from, attr))
with bpy.data.libraries.load(filepath) as (data_src, data_dst):
for attr in dir(data_dst):
setattr(data_dst, attr, getattr(data_src, attr))
# The loaded objects can be accessed from 'data_to' outside of the context
# The loaded objects can be accessed from `data_dst` outside of the context
# since loading the data replaces the strings for the data-blocks or None
# if the data-block could not be loaded.
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.meshes = data_from.meshes
with bpy.data.libraries.load(filepath) as (data_src, data_dst):
data_dst.meshes = data_src.meshes
# Now operate directly on the loaded data.
for mesh in data_to.meshes:
for mesh in data_dst.meshes:
if mesh is not None:
print(mesh.name)