Export_3ds: Added distance cue chunk export
[blender-addons.git] / pose_library / pose_usage.py
blob1a85f56ec55233e00e5cefa9e7dd63270ed1c50c
1 # SPDX-FileCopyrightText: 2021-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """
6 Pose Library - usage functions.
7 """
9 from typing import Set
10 import re
11 import bpy
13 from bpy.types import (
14 Action,
15 Object,
19 def select_bones(arm_object: Object, action: Action, *, select: bool, flipped: bool) -> None:
20 pose_bone_re = re.compile(r'pose.bones\["([^"]+)"\]')
21 pose = arm_object.pose
23 seen_bone_names: Set[str] = set()
25 for fcurve in action.fcurves:
26 data_path: str = fcurve.data_path
27 match = pose_bone_re.match(data_path)
28 if not match:
29 continue
31 bone_name = match.group(1)
33 if bone_name in seen_bone_names:
34 continue
35 seen_bone_names.add(bone_name)
37 if flipped:
38 bone_name = bpy.utils.flip_name(bone_name)
40 try:
41 pose_bone = pose.bones[bone_name]
42 except KeyError:
43 continue
45 pose_bone.bone.select = select
48 if __name__ == '__main__':
49 import doctest
51 print(f"Test result: {doctest.testmod()}")