AE(After Effects) Expressions and Scripts
1.17K subscribers
3 photos
15 videos
14 files
8 links
Usefull expression and scripts for AE (After Effects). Automate your routine, speed up motion design process with the power of coding.
Download Telegram
Convert the one layer space to another layer Anchor point coordinates with toComp functions:

var layer = thisComp.layer("Some layer")
layer.toComp(layer.anchorPoint)

For gradient ramp or similar effects that used coordinates. If you need to live it on the same place despite changing the position or scale:

toComp(anchorPoint + value)

https://www.youtube.com/watch?v=xeBrtrrKDVA
Scale in pixels in After Effects using Expressions

var targetSize = [500, 500];
var sr = thisLayer.sourceRectAtTime(time);
[targetSize[0] / sr.width * 100, targetSize[1] / sr.height * 100];
Center Text Anchor Point script ⚓️⚓️⚓️

a = thisLayer.sourceRectAtTime();
height = a.height;
width = a.width;
top = a.top;
left = a.left;

x = left + width/2;
y = top + height/2;
[x,y];
This media is not supported in your browser
VIEW IN TELEGRAM
Copy layer position vertically from center with index offset↕️

Apply to Position
Cmd/Ctrl + D to dublicate layer

var width = thisLayer.sourceRectAtTime(time).width; var height = thisLayer.sourceRectAtTime(time).height; var compWidth = thisComp.width/2; var compHeight = thisComp.height/2; var thisIndex = index-1; var count = thisIndex % 2; var step = Math.round(thisIndex/2); if (count == 1) { y = compHeight + height * step; } else{ y = compHeight - height * step; } [compWidth, y]
This media is not supported in your browser
VIEW IN TELEGRAM
Text Typewriter Effect⌨️

All you need to do is to set the time to the number of letters in our text.
Apply to Source Text of text layer.


// properties you can change
var startAt = 0;
var endAt = 9;

// trim the text
var maxLetters = Math.floor(linear(time, startAt, endAt, 0, value.length)); // number
var result = value.substring(0, maxLetters); // trim
result
Countsown.aep
1.8 MB
Countdown Timer

With ability to set mm:ss and delay parameters.
Apply to Source Text property.
Project file included. JS.

var wait = 0; //seconds before countdown starts var mm = 0; //minutes var ss = 10;// seconds mm = mm * 60; var totalSec = ss + mm + wait; ClockTimeNumber = Math.floor(totalSec - time); function addZero(n) { if (n<10) { return "0" + n; } else { return n;} } minutes = (Math.floor(ClockTimeNumber/60)%60); seconds = ClockTimeNumber%60; if (totalSec > 0 && time < totalSec) { addZero(minutes) + ":" + addZero(seconds); } else {"00:00"}
rd_scripts_20170108.zip
173 KB
Usefull free ReDefinery Scripts.
The site is 'offline for now so you can download it from here.
This media is not supported in your browser
VIEW IN TELEGRAM
Blinking expression💡
Apply to Opacity

blinkRate = 20;
n=Math.sin(time*blinkRate);
if(n<0) 0; else 100;
This media is not supported in your browser
VIEW IN TELEGRAM
Range Mapper ↔️

Change the default slider control min and max values to your custom numbers.

input = effect("Slider Control")("Slider");

inputLow = 0; // default min value
inputHigh = 100; // default max value
outputLow = 466; // new min value
outputHigh = 618; // new max value

linear(input,inputLow,inputHigh,outputLow,outputHigh)


You can learn more about linear expression from this tutorial:
https://www.youtube.com/watch?v=2h9ZfUHVG6Q
👍2
⌨️Type On Effect Text Animation
Based on letter index

Apply to Source text

//Slider Name: Text
//Checkbox Name: On/Off

var sign = "|"; // change the blinking sign to "▌"or "_"
var blinkInterval = 15; // edit the blinking interval in frames
// slider with text length
var i = effect("Text")("ADBE Slider Control-0001");
// checkbox to turn the cursor on and off
var on = effect("On/Off")("ADBE Checkbox Control-0001");

var frames = timeToFrames(time);

var check = frames / blinkInterval;

if (on == 1) {
if (i.valueAtTime(time + thisComp.frameDuration) > i) {
end = sign;
} else {
if (Math.floor(check) % 2 == 0) {
end = sign;
} else {
end = " ";
}
}
} else {
end = " ";
}

text.sourceText.substr(0,parseInt(i)) + end;

https://www.youtube.com/watch?v=U6HxvLm-ADA&t=429s
This media is not supported in your browser
VIEW IN TELEGRAM
SourceRectAtTime() + Scale

By the default SourceRectAtTime()do not include Scale property so here is the script that include Scale factor.

width = thisComp.layer("blue").sourceRectAtTime().width;
height = thisComp.layer("blue").sourceRectAtTime().height;
thisScalePercentage = thisComp.layer("blue").transform.scale[0] / 100;
widthScale = width * thisScalePercentage;
heightScale = height * thisScalePercentage;
[widthScale, widthScale]
This media is not supported in your browser
VIEW IN TELEGRAM
Here is a quick tip to lock the object to the center of composition.

Position property:
[thisComp.width/2, thisComp.height/2]

Anchor point:
a = thisLayer.sourceRectAtTime(); height = a.height; width = a.width; top = a.top; left = a.left; x = left + width/2; y = top + height/2; [x,y];
1
This media is not supported in your browser
VIEW IN TELEGRAM
Image content fill into mask shape layer

Apply to Scale property

let mask = thisComp.layer("mask");
let imgWidth = thisLayer.sourceRectAtTime().width;
let imgHeight = thisLayer.sourceRectAtTime().height;
let maskScaleX = mask.transform.scale[0] / 100;
let maskScaleY = mask.transform.scale[1] / 100;
let maskWidth = mask.sourceRectAtTime().width * maskScaleX;
let maskHeight = mask.sourceRectAtTime().height * maskScaleY;
let scaleToX = maskWidth / imgWidth * 100;
let scaleToY = maskHeight / imgHeight * 100;
if (scaleToX >= scaleToY) {
scale = scaleToX;
} else if (scaleToY > scaleToX) {
scale = scaleToY;
} [scale, scale]
2👍2
This media is not supported in your browser
VIEW IN TELEGRAM
Parallax animation
The easy to use and customize parallax animation for multiply object. You just need to animate null (or other layer) position, then apply the multiply index value with slider contol for each layer.

Apply to position property:

let nullRefer = thisComp.layer("Null 1");
let multyplyerSlider = effect("index")("Slider");
let xReffer = nullRefer.transform.position[0] * multyplyerSlider;
let yReffer = nullRefer.transform.position[1] * multyplyerSlider;
let thisX = transform.position.value[0];
let thisY = transform.position.value[1];
x = thisX + xReffer;
y = thisY + yReffer;
[x, y]
👍1
This media is not supported in your browser
VIEW IN TELEGRAM
Custom variables based animation 🤔

I want to show you very specific trick witch allow you to animate object position of the layer with changeable size. It's allow you to animate objects based on variable(like Width, Height etc.) you have set inside expression and multiply by keyframe values that you set on the timeline. In this example below the keyframe values are set to -1, 0, 1. The position of the text animate from left side to center and right side does not matter what the length of the text.

let xValue = value[0];
let yValue = value[1];
let xCenter = thisComp.width / 2; let yCenter = thisComp.height / 2;
let layerWidth = thisLayer.sourceRectAtTime().width;
let layerHeight = thisLayer.sourceRectAtTime().height;
let thisScalePercentage = transform.scale[0]/100;
let widthScale = layerWidth * thisScalePercentage;
let heightScale = layerHeight * thisScalePercentage;
x = (xValue * (thisComp.width + widthScale) / 2) + xCenter;
y = (yValue * (thisComp.height + heightScale) / 2) + yCenter;
[x , yCenter]