-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoperators.py
More file actions
70 lines (57 loc) · 2.1 KB
/
operators.py
File metadata and controls
70 lines (57 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# SPDX-License-Identifier: GPL-3.0-or-later
from typing import Set
import bpy
from bpy.types import Operator
from bpy.types import Context
from .utils import (
dprint,
process_bone_conversion,
store_initial_state,
restore_initial_state,
init_progress,
finish_progress,
is_any_pose_bone_selected,
)
from .bl_logger import logger
class CRM_OT_convert_rotation_mode(Operator):
"""Convert the selected pose bone's rotation mode."""
bl_idname = "crm.convert_rotation_mode"
bl_label = "Convert Rotation Mode"
bl_description = "Convert the selected bone's rotation mode."
bl_options = {'UNDO', 'INTERNAL'}
@classmethod
def poll(cls, context: Context) -> bool:
"""Filter for pose mode, selected bones"""
is_pose_mode = context.mode == 'POSE'
has_selected_bones = is_any_pose_bone_selected()
return is_pose_mode and has_selected_bones
def execute(self, context: Context) -> Set[str]:
"""main execution - convert rotation modes for selected bones."""
target_rmode = context.scene.CRM_Properties.targetRmode
selected_bone_names = [
bone.name for bone in context.selected_pose_bones
]
bone_count = len(selected_bone_names)
dprint(
f"Starting conversion for {bone_count} bones: "
f"{selected_bone_names}"
)
store_initial_state(context)
init_progress(context, bone_count)
# Process each bone by name
for bone_name in selected_bone_names:
if bone_name in context.object.pose.bones:
current_bone = context.object.pose.bones[bone_name]
process_bone_conversion(context, current_bone)
else:
dprint(f"Warning: Bone '{bone_name}' not found.")
logger.info(" # No more bones to work on.")
# Progress cleanup
finish_progress(context)
self.report(
{"INFO"},
f"Successfully converted {bone_count} bone(s) to "
f"'{target_rmode}'"
)
restore_initial_state(context)
return {'FINISHED'}