Advertisement
nipapin

shrink keys

Jan 25th, 2022
813
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shrink() {
  2.         if (!(app.project.activeItem instanceof CompItem)) return;
  3.  
  4.         var currentComposition = app.project.activeItem;
  5.  
  6.         if (!currentComposition.selectedProperties.length) return;
  7.  
  8.         var properties = currentComposition.selectedProperties;
  9.  
  10.         app.beginUndoGroup("Shrink Keys");
  11.  
  12.         for (var index = 0; index < properties.length; index++) {
  13.             var keyframeData = [];
  14.             var property = properties[index];
  15.  
  16.             if (!property.numKeys) continue;
  17.  
  18.             for (var keyIndex = 1; keyIndex <= property.numKeys; keyIndex++) {
  19.                 keyframeData.push(property.keyValue(keyIndex));
  20.             }
  21.  
  22.             for (var keyIndex = 0; keyIndex < keyframeData.length; keyIndex++) {
  23.                 var keyframeValue = keyframeData[keyIndex];
  24.                 var time = keyIndex * currentComposition.frameDuration;
  25.                 property.setValueAtTime(time, keyframeValue);
  26.             }
  27.  
  28.             for (var keyIndex = property.numKeys; keyIndex > keyframeData.length; keyIndex--) {
  29.                 property.removeKey(keyIndex);
  30.             }
  31.         }
  32.         app.endUndoGroup();
  33.     }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement