ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trying to get a function from a text source via expressions : line break break the atempt ...

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nicolas Guionnet
Trying to get a function from a text source via expressions : line break break the atempt ...
on Mar 7, 2019 at 1:42:04 pm

Hi !

It seems there is no natural way to use global functions in AE. (it really complicates my daily life these days ...)
I tried to define two such functions in a text layer and access them in an expression :

monCode = thisComp.layer("CODE -----JS -----").text.sourceText.value
eval(monCode);

It doesn't work because of the line breaks in the code of my global function. In fact when I strip the string of its line feeds (with a text editor) it works. :
(but living in a line-break-less world is a nightmare.)
I tried this :

monCode = thisComp.layer("CODE -----JS -----").text.sourceText.value
monCode = monCode.replace(/(\r\n|\n|\r)/gm, " ");
eval(monCode);

It does no good.
In fact the js code of my global function seems to be ignored in the text source property if there is a line break in it.

Anybody knowing a solution ?

And BTW, do you know why these necessary-obvious-basic global functions are not present in AE.
Is there a plugin doing this ?

T-H-A-N-K-S !

monCode = thisComp.layer("CODE -----JS -----").text.sourceText.value
eval(monCode);

then :

monCode = thisComp.layer("CODE -----JS -----").text.sourceText.value
monCode = monCode.replace(/(\r\n|\n|\r)/gm, " ");
eval(monCode);



Return to posts index

Dan Ebberts
Re: Trying to get a function from a text source via expressions : line break break the atempt ...
on Mar 7, 2019 at 5:01:34 pm

If I create a text layer named "CODE -----JS -----" that looks like this:

function square(a){
return a*a;
}


And then on another layer use this expression:

monCode = thisComp.layer("CODE -----JS -----").text.sourceText.value
eval(monCode);
square (10)

I get 100, as expected. I'm not sure where you're running into trouble.


Dan



Return to posts index

Nicolas Guionnet
Re: Trying to get a function from a text source via expressions : line break break the atempt ...
on Mar 7, 2019 at 8:23:38 pm

Thanks Dan !

Well, it's embarrassing. I've just created a new test file. I did (nearly) the same things. And then everything works.
... I have been struggling too many hours for this, and you just showed me there is nothing to worry about.

Note that the layer using the function is a shape layer ... I will try to solve this tomorrow ... and I'll let you know ...

But I am really glad : I will be using (a sort of) global functions ...


Return to posts index


Tomas Bumbulevičius
Re: Trying to get a function from a text source via expressions : line break break the atempt ...
on Mar 7, 2019 at 5:08:59 pm
Last Edited By Tomas Bumbulevičius on Mar 7, 2019 at 5:10:12 pm

Try appending your replace part with \x03. It should help to finalise all breaks scenarios.

Find out more:
After Effects Tutorials: motion design, expressions, scripting.


Return to posts index

Nicolas Guionnet
Re: Trying to get a function from a text source via expressions : line break break the atempt ...
on Mar 7, 2019 at 8:25:39 pm

Thanks Tomas !
I was looking for the right character code ... until Dan Showed me that there is no need to remove breaks ... ☺
I will try to find the reason for my troubles tomorrow ...


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]