1
+ /**
2
+ * @name Round Selected Keyframe Value(s)
3
+ * @version 1.0
4
+ * @author Kyle Martinez <www.kyle-martinez.com>
5
+ *
6
+ * @description Round the values for all selected keyframes to the nearest whole number. Currently
7
+ * works with 1 dimensional properties (Opacity, Rotation, etc.), 2 dimensional properties
8
+ * (2D Scale, 2D Position, etc.), and 3 dimensional properties (3D Scale, 3D Position, etc.).
9
+ *
10
+ * @license This script is provided "as is," without warranty of any kind, expressed or implied. In
11
+ * no event shall the author be held liable for any damages arising in any way from the use of this
12
+ * script.
13
+ *
14
+ * In other words, I'm just trying to help make life as an animator easier
15
+ * "A rising tide lifts all boats." - John F. Kennedy, 1963
16
+ */
17
+
18
+ ( function roundSelectedKeyframeValues ( ) {
19
+ function roundValue ( oldValue ) {
20
+ return Math . round ( oldValue ) ;
21
+ }
22
+
23
+ function roundValues ( oldValues ) {
24
+ var newValues = [ ] ;
25
+ var numOldValues = oldValues . length ;
26
+ for ( var v = 0 ; v < numOldValues ; v ++ ) {
27
+ newValues . push ( roundValue ( oldValues [ v ] ) ) ;
28
+ }
29
+ return newValues ;
30
+ }
31
+
32
+ function roundKeyframeValues ( property ) {
33
+ var propertyValueType = property . propertyValueType ;
34
+ var keys = property . selectedKeys ;
35
+ var numKeys = keys . length ;
36
+ for ( var k = 0 ; k < numKeys ; k ++ ) {
37
+ var index = keys [ k ] ;
38
+ var oldKeyValue = property . keyValue ( index ) ;
39
+ var newKeyValue = oldKeyValue ;
40
+ switch ( propertyValueType ) {
41
+ case PropertyValueType . OneD :
42
+ newKeyValue = roundValue ( oldKeyValue ) ;
43
+ break ;
44
+ case PropertyValueType . TwoD :
45
+ case PropertyValueType . TwoD_SPATIAL :
46
+ case PropertyValueType . ThreeD :
47
+ case PropertyValueType . ThreeD_SPATIAL :
48
+ newKeyValue = roundValues ( oldKeyValue ) ;
49
+ break ;
50
+ default :
51
+ break ;
52
+ }
53
+ property . setValueAtKey ( index , newKeyValue ) ;
54
+ }
55
+ }
56
+
57
+ app . beginUndoGroup ( "Round Selected Keyframe Value(s)" ) ;
58
+ var comp = app . project . activeItem ;
59
+ var properties = comp . selectedProperties ;
60
+ var numProperties = properties . length ;
61
+ for ( var p = 0 ; p < numProperties ; p ++ ) {
62
+ var property = properties [ p ] ;
63
+ if ( property . propertyType === PropertyType . PROPERTY ) {
64
+ if ( property . isTimeVarying === true ) {
65
+ roundKeyframeValues ( property ) ;
66
+ }
67
+ }
68
+ }
69
+ app . endUndoGroup ( ) ;
70
+ } ) ( ) ;
0 commit comments