Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare functions in a custom global library in After Effects?

Is it possible to save all my custom expressions inside an external .jsx file, so I can call them from inside my projects?

For example, let's say I have an expression I use a lot, that ties a puppet tool point to a null object's position. I know I can I transform that expression into a function that could take, say, two arguments, but can I save it into a custom library, so that I can easily re-use it inside the project?

Right now, I'm simply copying and pasting the same code from property to property, and I'm beginning to feel there is an alternative way to do this more efficiently.

Thanks in advance!

like image 511
CCrawler Avatar asked Nov 04 '22 07:11

CCrawler


1 Answers

I tested this with success, put this on top of your expression:

$.evalFile("/Users/myname/ae/functions.txt");

Then you can access whatever functions you have in your functions.txt file.

See here for more details: https://forums.creativecow.net/readpost/227/29337

The problem with this method is that you still need to include the extra line for each expression.

Anyway here is my complete setup, just in case: my expression is:

$.evalFile("/Users/myname/ae/functions.txt");

var p1  = thisComp.layer("Null 1").transform.position;
var p2  = thisComp.layer("Null 4").transform.position;
var p = p2 - p1;

printPosition(p)

And my functions.txt file contains the following:

function printPosition (p){
    return " " + parseInt(p[0]) + " : " + parseInt(p[1])
}
like image 103
ling Avatar answered Nov 08 '22 05:11

ling