ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Replacing a string of text from a text file (with a small twist)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
David Newman
Replacing a string of text from a text file (with a small twist)
on Oct 2, 2019 at 10:29:54 pm

Hi there,

I have an expression on my text layer which evaluates a variable in a text file to get a string:

$.evalFile("/D:/main.txt");
eval(thisLayer.name)

And inside the main.txt:
string1 = "Hello world"

And finally the text layer name is appropriately called "string1" so that the string is evaulated correctly and the text on screen is "Hello world".

What I really want to do is to have more than one strings in my text file, like this:
string1 = "Hello world"
string2 = "Hello Mars"
string3 = "Hello Pluto"
text1 = "Human"
text2 = "Martian"
text3 = "Plutonian"

And I want to define multiple strings by having two text layers called "string" and "text" and having a null object above simply called 1, 2 or 3 to change the text.
And have the expression as:

$.evalFile("/D:/main.txt");
eval(thisLayer.name+(index-1))

But it doesn't work. Hope this vaguely makes sense. I've managed to achieve the effect adding the layer name to a slider value, but I'd rather do it with another layer. Thanks.


Return to posts index

Dan Ebberts
Re: Replacing a string of text from a text file (with a small twist)
on Oct 2, 2019 at 11:35:50 pm

I think you're maybe making it more complicated than it needs to be. If you use this as your text file:

string1 = "Hello world"
string2 = "Hello Mars"
string3 = "Hello Pluto"
text1 = "Human"
text2 = "Martian"
text3 = "Plutonian"

Then once you do this:

$.evalFile("/D:/main.txt");

those six variables (string1, string2, etc) should exist in the expression.

So this:

$.evalFile("/D:/main.txt");
string2

Should give you "Hello Mars", so I wouldn't think you'd need to do an eval() to select which string gets displayed.

It might be even better to do something like this with your text file:

strings = ["Hello world", "Hello Mars", "Hello Pluto"];
texts = ["Human", "Martian", "Plutonian"];

Then an expression like this:


$.evalFile("/D:/main.txt");
idx = 2;
strings[idx] + "\r" + texts[idx]


Would give you:

Hello Pluto
Plutonian

Then you just need a clever way to select idx...

Dan



Return to posts index

David Newman
Re: Replacing a string of text from a text file (with a small twist)
on Oct 3, 2019 at 3:44:23 pm

Thanks for your reply, Dan.

Lots of useful tips in there!


Return to posts index

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