AE expressions sink

· Adobe After Effects · Adobe After Effects MOC · #code/js ·

TOC

Conversion

.toFixed(0) rounding method

Strings

{string}.split(" - ") splits string into array
{string}.indexOf("search string") search and returns the position of substring inside string .indexOf("string") > -1
{string}.substring(position,[length]) extracts substring

Clamping

ClampX = Math.max(Math.min(EMposCorr[0], 160), -160);
ClampY = Math.max(Math.min(EMposCorr[1], -200), -470);
[ClampX, ClampY, EMposCorr[2]]

there's actually a Clamp function

Text styles

Text styles docs

Loop Mask Animation

if (numKeys > 1 && time > key(numKeys).time){  
	t1 = key(1).time;  
	t2 = key(numKeys).time;  
	span = t2 - t1;  
	delta = time - t2;  
	t = delta%span;  
	valueAtTime(t1 + t)  
} else  
	value

Opacity from Parent with editability

(hasParent) ? (parent.opacity/100) * value : value;

Wheel rotation

distance = position[0];  
circumference = width*Math.PI;  
rptation = distance/circumference*360;

Layer marker to drive properties

Drive layer opacity by a marker (and its duration), use this code for Opacity property

kp = thisLayer.marker.key("fadein"); // You have to create a marker with name `fadein` and set its duration
linear(time, kp.time, kp.time + kp.duration, 0, 100)

// or use curve instead of linear
ease(time, kp.time, kp.time + kp.duration, 0, 100)

// marker can be also retrieved by its index instead of the name (starting at 1)
kp = thisLayer.marker.key(1);

Referencing properties

thisProperty.propertyGroup(1).name
thisProperty.propertyGroup(1).propertyIndex

Path properties

{pathproperty}.points(t=time)
Returns array of pairs [x,y][x,y]...[x,y]

{pathproperty}.inTangents(time=t)
{pathproperty}.outTangents(time=t)
{pathproperty}.isClosed() - boolean
{pathproperty}.pointOnPath(percentage=0.5, time=t) - [x,y]
{pathproperty}.tangentOnPath(percentage=0.5, time=t) - [x,y] outgoing tangent
{pathproperty}.normalOnPath(percentage=0.5, time=t) - [x,y]

Create Path

{pathproperty}.createPath(points = [[],[],[]], inTangents = [], outTangents = [], isClosed = true)

Angle between 2 Vectors

Radians = acos(dot(normalize({vec1}, {vec2}));
Degrees = radToDegrees(acos(dot(normalize({vec1}), normalize({vec2}))

Motion direction (velocity)

v = position.velocity; //any spatial animation property
radiansToDegrees(Math.atan2(v[1], v[0])) + 90

Text styles

txt = l.text.sourceText;
stl = thisComp.layer({layer}).text.sourceText.style;
stl = txt.getStyleAt({char num},{time});
stl.setText(txt).setFillColor({color}).setTracking({tracking value})