1 # SPDX-License-Identifier: GPL-2.0-or-later
4 Pose Library - functions.
7 from pathlib
import Path
8 from typing
import Any
, List
, Iterable
15 def load_assets_from(filepath
: Path
) -> List
[Datablock
]:
16 if not has_assets(filepath
):
17 # Avoid loading any datablocks when there are none marked as asset.
20 # Append everything from the file.
21 with bpy
.data
.libraries
.load(str(filepath
)) as (
25 for attr
in dir(data_to
):
26 setattr(data_to
, attr
, getattr(data_from
, attr
))
28 # Iterate over the appended datablocks to find assets.
29 def loaded_datablocks() -> Iterable
[Datablock
]:
30 for attr
in dir(data_to
):
31 datablocks
= getattr(data_to
, attr
)
32 for datablock
in datablocks
:
36 for datablock
in loaded_datablocks():
37 if not getattr(datablock
, "asset_data", None):
40 # Fake User is lost when appending from another file.
41 datablock
.use_fake_user
= True
42 loaded_assets
.append(datablock
)
46 def has_assets(filepath
: Path
) -> bool:
47 with bpy
.data
.libraries
.load(str(filepath
), assets_only
=True) as (
51 for attr
in dir(data_from
):
52 data_names
= getattr(data_from
, attr
)