glTF: fix typo
[blender-addons.git] / pose_library / pose_usage.py
blob45a39e4df859b5d3d4484c1d232f79e5f3666143
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """
4 Pose Library - usage functions.
5 """
7 from typing import Set
8 import re
9 import bpy
11 from bpy.types import (
12 Action,
13 Object,
17 def select_bones(arm_object: Object, action: Action, *, select: bool, flipped: bool) -> None:
18 pose_bone_re = re.compile(r'pose.bones\["([^"]+)"\]')
19 pose = arm_object.pose
21 seen_bone_names: Set[str] = set()
23 for fcurve in action.fcurves:
24 data_path: str = fcurve.data_path
25 match = pose_bone_re.match(data_path)
26 if not match:
27 continue
29 bone_name = match.group(1)
31 if bone_name in seen_bone_names:
32 continue
33 seen_bone_names.add(bone_name)
35 if flipped:
36 bone_name = bpy.utils.flip_name(bone_name)
38 try:
39 pose_bone = pose.bones[bone_name]
40 except KeyError:
41 continue
43 pose_bone.bone.select = select
46 if __name__ == '__main__':
47 import doctest
49 print(f"Test result: {doctest.testmod()}")