Advertisement
Dotsarecool

Slide In Out AE Script

Nov 26th, 2022
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.     function SlideInOut(thisObj) {
  3.         var buttonWidth = 50, buttonHeight = 40, buttonBuffer = 2;
  4.         var mouseLocation = [300, 200];
  5.  
  6.         getMouseCoords();
  7.  
  8.         var easingPalette = new Window("palette", "Slide In & Out", undefined, {borderless:true});
  9.         easingPalette.bounds = [
  10.             mouseLocation[0]-buttonWidth*3,
  11.             mouseLocation[1]-buttonHeight*2,
  12.             mouseLocation[0]+buttonWidth*3,
  13.             mouseLocation[1]+buttonHeight*1];
  14.  
  15.         function getMouseCoords() {
  16.             var pos = [0, 0, 0, 0];
  17.             for (i = 0; i < $.screens.length; i++) {
  18.                 if ($.screens[i].top < pos[0]) pos[0] = $.screens[i].top;
  19.                 if ($.screens[i].bottom > pos[2]) pos[2] = $.screens[i].bottom;
  20.                 if ($.screens[i].left < pos[3]) pos[3] = $.screens[i].left;
  21.                 if ($.screens[i].right > pos[1]) pos[1] = $.screens[i].right;
  22.             }
  23.             var sizeX = pos[1] - pos[3];
  24.             var sizeY = pos[2] - pos[0];
  25.             var mouseCapWin = new Window("dialog", undefined, undefined, {borderless: true})
  26.             mouseCapWin.preferredSize.width = sizeX;
  27.             mouseCapWin.preferredSize.height = sizeY;
  28.             mouseCapWin.location = [pos[3], pos[0]];
  29.             mouseCapWin.opacity = 0.01;
  30.             var mouseCapGroup = mouseCapWin.add("group", undefined, {name: "mouseCapGroup"})
  31.             mouseCapGroup.preferredSize.width = sizeX;
  32.             mouseCapGroup.preferredSize.height = sizeY;
  33.             mouseCapGroup.spacing = 0;
  34.             mouseCapGroup.margins = 0;
  35.             mouseCapWin.addEventListener("mouseover", grabMousePos);
  36.             function grabMousePos(m){
  37.                 mouseLocation[0] = m.screenX;
  38.                 mouseLocation[1] = m.screenY;
  39.                 mouseCapWin.close();
  40.             }
  41.             mouseCapWin.show();
  42.         }
  43.  
  44.         function adjustTransitionPosition(comp, pos, val, scale) {
  45.             return [
  46.                 [val[0]+pos[0][0]*comp.width*1.5/scale[0]*100, val[1]+pos[0][1]*comp.height*1.5/scale[1]*100],
  47.                 [val[0]+pos[1][0]*comp.width*1.5/scale[0]*100, val[1]+pos[1][1]*comp.height*1.5/scale[1]*100]
  48.             ];
  49.         }
  50.  
  51.         function layerLonely(layers, i) {
  52.             if (layers[i].parent == null) return true;
  53.             for (var j = 0; j < layers.length; j++) {
  54.                 if (layers[i].parent == layers[j]) return false;
  55.             }
  56.             return true;
  57.         }
  58.  
  59.         function applyTransition() {
  60.             var comp = app.project.activeItem;
  61.             if (comp.constructor.name == "CompItem") {
  62.                 var easing = new KeyframeEase(0, 80.0);
  63.                 app.beginUndoGroup("Slide In & Out");
  64.  
  65.                 var layers = comp.selectedLayers;
  66.                 for (var i = 0; i < layers.length; i++) {
  67.                     if (layerLonely(layers, i)) {
  68.                         var val = layers[i].position.valueAtTime(comp.time, true);
  69.                         var key1 = layers[i].position.addKey(comp.time);
  70.                         var key2 = layers[i].position.addKey(comp.time + 2/3);
  71.  
  72.                         var scale = layers[i].parent == null ? [100,100,100] : layers[i].parent.scale.valueAtTime(comp.time, true);
  73.                         var pos = adjustTransitionPosition(comp, this.transition, val, scale);
  74.                         layers[i].position.setValueAtKey(key1, pos[0]);
  75.                         layers[i].position.setValueAtKey(key2, pos[1]);
  76.                        
  77.                         var arr = [easing];
  78.                         switch (layers[i].position.propertyValueType) {
  79.                             case PropertyValueType.ThreeD: arr.push(easing);
  80.                             case PropertyValueType.TwoD: arr.push(easing);
  81.                         }
  82.                         layers[i].position.setInterpolationTypeAtKey(key1, KeyframeInterpolationType.BEZIER, KeyframeInterpolationType.BEZIER);
  83.                         layers[i].position.setInterpolationTypeAtKey(key2, KeyframeInterpolationType.BEZIER, KeyframeInterpolationType.BEZIER);
  84.                         layers[i].position.setTemporalEaseAtKey(key1, arr, arr);
  85.                         layers[i].position.setTemporalEaseAtKey(key2, arr, arr);
  86.                     }
  87.  
  88.                     if (this.transition[0][0] + this.transition[0][1] == 0) {
  89.                         if (layers[i].outPoint > comp.time + 2/3)
  90.                             layers[i].outPoint = comp.time + 2/3;
  91.                     } else {
  92.                         if (layers[i].inPoint < comp.time)
  93.                             layers[i].inPoint = comp.time;
  94.                     }
  95.                 }
  96.  
  97.                 app.endUndoGroup();
  98.             }
  99.             close();
  100.         }
  101.  
  102.         function close() {
  103.             easingPalette.close();
  104.         }
  105.  
  106.         function addButton(palette, location, text, transition) {
  107.             var rect = [
  108.                 buttonBuffer+location[0]*buttonWidth,
  109.                 buttonBuffer+location[1]*buttonHeight,
  110.                 -buttonBuffer+(location[0]+1)*buttonWidth,
  111.                 -buttonBuffer+(location[1]+1)*buttonHeight];
  112.             var button = palette.add("button", rect, text);
  113.             button.transition = transition;
  114.             if (text == "X") button.onClick = close;
  115.             else button.onClick = applyTransition;
  116.             return button;
  117.         }
  118.  
  119.         function addText(palette, location, text) {
  120.             var rect = [
  121.                 buttonBuffer+location[0]*buttonWidth,
  122.                 buttonBuffer+(location[1]-1/3)*buttonHeight,
  123.                 -buttonBuffer+(location[0]+1)*buttonWidth,
  124.                 -buttonBuffer+(location[1]+1)*buttonHeight];
  125.             var label = palette.add("statictext", rect, text);
  126.             label.justify = "center";
  127.         }
  128.  
  129.         addText(easingPalette, [1, 1], "Slide\nIn");
  130.         addButton(easingPalette, [1, 0], "Up", [[0, -1],[0, 0]]);
  131.         addButton(easingPalette, [2, 1], "Right", [[1, 0],[0, 0]]);
  132.         addButton(easingPalette, [1, 2], "Down", [[0, 1],[0, 0]]);
  133.         addButton(easingPalette, [0, 1], "Left", [[-1, 0],[0, 0]]);
  134.         addText(easingPalette, [4, 1], "Slide\nOut");
  135.         addButton(easingPalette, [4, 0], "Up", [[0, 0],[0, -1]]);
  136.         addButton(easingPalette, [5, 1], "Right", [[0, 0],[1, 0]]);
  137.         addButton(easingPalette, [4, 2], "Down", [[0, 0],[0, 1]]);
  138.         addButton(easingPalette, [3, 1], "Left", [[0, 0],[-1, 0]]);
  139.         addButton(easingPalette, [2.5,0], "X", []);
  140.  
  141.         easingPalette.show();
  142.     }
  143.  
  144.     SlideInOut(this);
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement