-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml_setKey_mr_checkIfAnimCurvesSelected.py
92 lines (82 loc) · 3.54 KB
/
ml_setKey_mr_checkIfAnimCurvesSelected.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
"""
# ------------------------------------------------------------------------------ #
# SCRIPT: ml_setKey_mr_checkIfAnimCurvesSelected.py
# VERSION: 0001
#
# CREATORS: Maria Robertson (just added check for selected animation curves)
# CREDIT: Morgan Loomis (for ml_setKey.py and ml_utilities.py)
# ---------------------------------------
#
# ---------------------------------------
# DESCRIPTION:
# ---------------------------------------
# A script importing from Morgan Loomis' robust ml_setKey script (Revision 11):
# http://morganloomis.com/tool/ml_setKey/
#
# This script just adds the following check:
# - If mouse pointer is NOT above Graph Editor:
# - Set key as normal.
#
# - If mouse pointer IS above Graph Editor:
# - If any animation curve keys are selected, key on only them (ignoring any highlighted attributes in the channel box).
#
# My hotkey preference:
# - S : ml_setKey.setKey(selectedChannels=False, visibleInGraphEditor=False, keyKeyed=False, deleteSubFrames=False, insert=True, keyShapes=False)
#
# - ALT + S : ml_setKey_mr_checkIfAnimCurvesSelected.main()
#
# ---------------------------------------
# RUN COMMAND:
# ---------------------------------------
import importlib
import ml_setKey_mr_checkIfAnimCurvesSelected
importlib.reload(ml_setKey_mr_checkIfAnimCurvesSelected)
ml_setKey_mr_checkIfAnimCurvesSelected.main()
# ---------------------------------------
# REQUIREMENTS:
# ---------------------------------------
# This script uses ml_setKey.py from the ml_tools library.
# Follow instructions here for installation: http://morganloomis.com/tool/ml_setKey/
#
# ---------------------------------------
# CHANGELOG:
# ---------------------------------------
# 2023-12-29 - 0001:
# - First pass.
# ------------------------------------------------------------------------------ #
"""
import maya.cmds as cmds
import maya.mel as mel
import ml_setKey
def main():
connection = cmds.editor('graphEditor1GraphEd', query=True, mainListConnection=True)
visible_curves = mel.eval('expandSelectionConnectionAsArray "{}"'.format(connection))
selected_curves = []
current_panel = cmds.getPanel(underPointer=True)
# -------------------------------------------------------------------
# 01. IF MOUSE CURSOR IS NOT OVER GRAPH EDITOR.
# -------------------------------------------------------------------
if current_panel != 'graphEditor1':
personal_ml_setkey_settings()
# -------------------------------------------------------------------
# 01. IF MOUSE CURSOR IS GRAPH EDITOR.
# -------------------------------------------------------------------
else:
# If any of the visible curves in the Graph Editor have selected keys, key only them.
# Otherwise, key as normal.
if visible_curves:
for curve in visible_curves:
has_keys_selected = are_keys_selected_on_animation_curve(curve)
if has_keys_selected:
selected_curves.append(curve)
if selected_curves:
cmds.setKeyframe(selected_curves, insert=True)
else:
personal_ml_setkey_settings()
else:
personal_ml_setkey_settings()
def are_keys_selected_on_animation_curve(curve):
selected_keys = cmds.keyframe(curve, query=True, selected=True)
return bool(selected_keys)
def personal_ml_setkey_settings():
ml_setKey.setKey(selectedChannels=True, visibleInGraphEditor=False, keyKeyed=True, deleteSubFrames=False, insert=True, keyShapes=False)