1
+ # -= ml_keyValueDragger.py =-
2
+ # __ by Morgan Loomis
3
+ # ____ ___ / / http://morganloomis.com
4
+ # / __ `__ \/ / Revision 5
5
+ # / / / / / / / 2018-05-14
6
+ # /_/ /_/ /_/_/ _________
7
+ # /_________/
8
+ #
9
+ # ______________
10
+ # - -/__ License __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11
+ #
12
+ # Copyright 2018 Morgan Loomis
13
+ #
14
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
15
+ # this software and associated documentation files (the "Software"), to deal in
16
+ # the Software without restriction, including without limitation the rights to use,
17
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
18
+ # Software, and to permit persons to whom the Software is furnished to do so,
19
+ # subject to the following conditions:
20
+ #
21
+ # The above copyright notice and this permission notice shall be included in all
22
+ # copies or substantial portions of the Software.
23
+ #
24
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
27
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
28
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #
31
+ # ___________________
32
+ # - -/__ Installation __/- - - - - - - - - - - - - - - - - - - - - - - - - -
33
+ #
34
+ # Copy this file into your maya scripts directory, for example:
35
+ # C:/Documents and Settings/user/My Documents/maya/scripts/ml_keyValueDragger.py
36
+ #
37
+ # Run the tool in a python shell or shelf button by importing the module,
38
+ # and then calling the primary function:
39
+ #
40
+ # import ml_keyValueDragger
41
+ # ml_keyValueDragger.drag()
42
+ #
43
+ #
44
+ # __________________
45
+ # - -/__ Description __/- - - - - - - - - - - - - - - - - - - - - - - - - - -
46
+ #
47
+ # Scale keyframes to their default value by dragging in the viewport.
48
+ #
49
+ # ____________
50
+ # - -/__ Usage __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51
+ #
52
+ # Run the tool, and the cursor will turn into a hand. Left-click and hold in the
53
+ # viewport, and then drag either left or right to scale the key value up or down.
54
+ # If you have no keys selectd, the tool will act only on curves that are visibile
55
+ # in the graph editor. If there are no keys at the current frame, keys will be
56
+ # set.
57
+ #
58
+ #
59
+ # ___________________
60
+ # - -/__ Requirements __/- - - - - - - - - - - - - - - - - - - - - - - - - -
61
+ #
62
+ # This script requires the ml_utilities module, which can be downloaded here:
63
+ # https://raw.githubusercontent.com/morganloomis/ml_tools/master/ml_utilities.py
64
+ #
65
+ # __________
66
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /_ Enjoy! _/- - -
67
+
68
+ __author__ = 'Morgan Loomis'
69
+ __license__ = 'MIT'
70
+ __revision__ = 5
71
+ __category__ = 'animation'
72
+
73
+ shelfButton = {'annotation' : 'Adjust the value of the current key by dragging in the viewport.' ,
74
+ 'command' : 'import ml_keyValueDragger;ml_keyValueDragger.drag()' ,
75
+ 'order' : 13 }
76
+
77
+ import maya .cmds as mc
78
+ import maya .mel as mm
79
+ from maya import OpenMaya
80
+
81
+ try :
82
+ import ml_utilities as utl
83
+ utl .upToDateCheck (32 )
84
+ except ImportError :
85
+ result = mc .confirmDialog ( title = 'Module Not Found' ,
86
+ message = 'This tool requires the ml_utilities module. Once downloaded you will need to restart Maya.' ,
87
+ button = ['Download Module' ,'Cancel' ],
88
+ defaultButton = 'Cancel' , cancelButton = 'Cancel' , dismissString = 'Cancel' )
89
+
90
+ if result == 'Download Module' :
91
+ mc .showHelp ('http://morganloomis.com/tool/ml_utilities/' ,absolute = True )
92
+
93
+ def drag ():
94
+ '''The primary command to run the tool'''
95
+ KeyValueDragger ()
96
+
97
+
98
+ class KeyValueDragger (utl .Dragger ):
99
+ '''Creates the tool and manages the data'''
100
+
101
+ def __init__ (self ,
102
+ name = 'mlKeyValueDraggerContext' ,
103
+ minValue = 0 ,
104
+ maxValue = None ,
105
+ defaultValue = 1 ,
106
+ title = 'Scale' ):
107
+
108
+ self .keySel = utl .KeySelection ()
109
+ selected = False
110
+ if self .keySel .selectedKeys ():
111
+ selected = True
112
+ pass
113
+ elif self .keySel .visibleInGraphEditor ():
114
+ self .keySel .setKeyframe ()
115
+ elif self .keySel .keyedChannels ():
116
+ self .keySel .setKeyframe ()
117
+ elif self .keySel .selectedObjects ():
118
+ self .keySel .setKeyframe ()
119
+
120
+ if not self .keySel .initialized :
121
+ return
122
+
123
+ utl .Dragger .__init__ (self , defaultValue = defaultValue , minValue = minValue , maxValue = maxValue , name = name , title = title )
124
+
125
+ self .time = dict ()
126
+ self .default = dict ()
127
+ self .value = dict ()
128
+ self .curves = self .keySel .curves
129
+
130
+ for curve in self .curves :
131
+ if selected :
132
+ self .time [curve ] = mc .keyframe (curve , query = True , timeChange = True , sl = True )
133
+ self .value [curve ] = mc .keyframe (curve , query = True , valueChange = True , sl = True )
134
+ else :
135
+ self .time [curve ] = self .keySel .time
136
+ self .value [curve ] = mc .keyframe (curve , time = self .keySel .time , query = True , valueChange = True )
137
+
138
+ #get the attribute's default value
139
+ node , attr = mc .listConnections ('.' .join ((curve ,'output' )), source = False , plugs = True )[0 ].split ('.' )
140
+ self .default [curve ] = mc .attributeQuery (attr , listDefault = True , node = node )[0 ]
141
+
142
+ self .setTool ()
143
+ onscreenInstructions = 'Drag left to scale toward default, and right to go in the opposite direction.'
144
+ self .drawString (onscreenInstructions )
145
+ OpenMaya .MGlobal .displayWarning (onscreenInstructions )
146
+
147
+
148
+ def dragLeft (self ):
149
+ '''
150
+ Activated by the left mouse button, this scales keys toward or away from their default value.
151
+ '''
152
+ self .drawString ('Scale ' + str (int (self .x * 100 ))+ ' %' )
153
+ for curve in self .curves :
154
+ for i ,v in zip (self .time [curve ], self .value [curve ]):
155
+ mc .keyframe (curve , time = (i ,), valueChange = self .default [curve ]+ ((v - self .default [curve ])* self .x ))
156
+
157
+
158
+
159
+ # ______________________
160
+ # - -/__ Revision History __/- - - - - - - - - - - - - - - - - - - - - - - -
161
+ #
162
+ # Revision 2: 2014-03-01 : Added revision notes, adding category
163
+ #
164
+ # Revision 3: 2016-05-01 : Bug fix
165
+ #
166
+ # Revision 4: 2016-05-02 : Actual bug fix
167
+ #
168
+ # Revision 5: 2018-05-14 : Shelf support.
0 commit comments