-
Notifications
You must be signed in to change notification settings - Fork 0
/
mr_selectKeys.py
123 lines (108 loc) · 4.6 KB
/
mr_selectKeys.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
# ------------------------------------------------------------------------------------------------------------------------------------------------
# SCRIPT: mr_selectKeys.py
# VERSION: 0006
#
# CREATORS: Maria Robertson
# CREDIT: Brian Horgan / Jørn-Harald Paulsen
# -------------------------------------------------------------------
# Last tested for Autodesk Maya 2023.3
# ---------------------------------------
# DESCRIPTION:
# ---------------------------------------
# Select keys of selected objects in the Graph Editor.
# Use one of the selection modes.
# - "playback_range" - Select keys only within the Playback Range.
# - "all" - Select all keys in the Graph Editor.
# - "currentTime" - Select keys that are only on the current frame.
#
# EXAMPLE USES:
# ---------------------------------------
# Found using "playback_range" helpful when animating scenes with multiple shots inside.
#
# ---------------------------------------
# RUN COMMAND:
# ---------------------------------------
import importlib
import mr_selectKeys
importlib.reload(mr_selectKeys)
# USE ONE OF THE FOLLOWING:
mr_selectKeys.main("playback_range")
mr_selectKeys.main("currentTime")
mr_selectKeys.main("all")
# ---------------------------------------
# RESEARCH THAT HELPED:
# ---------------------------------------
# https://help.autodesk.com/cloudhelp/2017/CHS/Maya-Tech-Docs/Commands/selectKey.html
#
# This script started as a modification of a script Brian Horgan kindly provided on CGSociety, with snippets from Jørn-Harald Paulsen's jh_getKeyObjs:
# https://forums.cgsociety.org/t/selecting-all-keys-on-a-certain-frame/1563705/2
#
# ---------------------------------------
# CHANGELOG:
# ---------------------------------------
# 2024-01-16 - 0006:
# - Minor formatting and changes.
#
# 2023-12-30 - 0005:
# - Typo fix.
#
# 2023-12-30 - 0004:
# - Rename from mr_select_graphEditor_keys.py.
#
# 2023-12-29 - 0003:
# - Combining with old MEL scripts, mr_select_currentFrameKeysOnVisibleCurvesOfSelected.mel and mr_select_currentFrameKeysOfSelected.mel.
#
# 2023-12-17 - 0002:
# - Converted original MEL script.
# - Made option to select all visible keys, or just those within the playback range.
#
# 2022-10-03 - 0001:
# - First original MEL script.
# ------------------------------------------------------------------------------------------------------------------------------------------------
"""
import maya.cmds as cmds
# ------------------------------------------------------------------------------ #
def main(selection_mode=None):
# -------------------------------------------------------------------
# 01. INITIALISE VARIABLES
# -------------------------------------------------------------------
selection = cmds.ls(selection=True)
if not selection:
cmds.warning("No selected items found.")
return
# deselect_unkeyed_objects(selection)
visible_animation_curves = cmds.animCurveEditor('graphEditor1GraphEd', query=True, curvesShown=True)
if not visible_animation_curves:
cmds.warning("No visible animation curves found.")
return
cmds.selectKey(clear=True)
# -------------------------------------------------------------------
# 01. PICK A SELECTION TYPE.
# -------------------------------------------------------------------
# Select keys only within the playback range.
if selection_mode == "playback_range":
start_time = cmds.playbackOptions(query=True, min=True)
end_time = cmds.playbackOptions(query=True, max=True)
for curve in visible_animation_curves:
cmds.selectKey(curve, toggle=True, time=(start_time, end_time), add=True)
# Select all keys.
if selection_mode == "all":
for curve in visible_animation_curves:
cmds.selectKey(curve, toggle=True)
# Select keys only at the current time.
if selection_mode == "currentTime":
current_time = cmds.currentTime(query=True)
for curve in visible_animation_curves:
cmds.selectKey(curve, toggle=True, time=(current_time, current_time))
##################################################################################################################################################
########################################################################
# #
# SUPPORTING FUNCTIONS #
# #
########################################################################
def deselect_unkeyed_objects(selection):
new_selection = [obj for obj in selection if cmds.keyframe(obj, query=True, keyframeCount=True) != 0]
if new_selection:
cmds.select(new_selection, replace=True)
return new_selection