1 # SPDX-FileCopyrightText: 2021-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 Pose Library - functions.
9 from pathlib
import Path
10 from typing
import Any
, List
, Iterable
17 def load_assets_from(filepath
: Path
) -> List
[Datablock
]:
18 if not has_assets(filepath
):
19 # Avoid loading any datablocks when there are none marked as asset.
22 # Append everything from the file.
23 with bpy
.data
.libraries
.load(str(filepath
)) as (
27 for attr
in dir(data_to
):
28 setattr(data_to
, attr
, getattr(data_from
, attr
))
30 # Iterate over the appended datablocks to find assets.
31 def loaded_datablocks() -> Iterable
[Datablock
]:
32 for attr
in dir(data_to
):
33 datablocks
= getattr(data_to
, attr
)
34 for datablock
in datablocks
:
38 for datablock
in loaded_datablocks():
39 if not getattr(datablock
, "asset_data", None):
42 # Fake User is lost when appending from another file.
43 datablock
.use_fake_user
= True
44 loaded_assets
.append(datablock
)
48 def has_assets(filepath
: Path
) -> bool:
49 with bpy
.data
.libraries
.load(str(filepath
), assets_only
=True) as (
53 for attr
in dir(data_from
):
54 data_names
= getattr(data_from
, attr
)