Page 1 of 1

including external text file in an expression

Posted: May 17th, 2010, 9:01 am
by amitzinman
My expression is as follows:

#include 'file:///f:/collager/texts.txt';
try{eval(thisLayer.name)}catch(err){"not found"}


and I am applying it to the Source Text property of a text layer.
However, for some reason I am getten a Syntax Error on this.

What am I doing wrong?

Re: including external text file in an expression

Posted: May 17th, 2010, 2:59 pm
by nab
You can read a file and eval its content using evalFile, like this:

Code: Select all

$.evalFile(path_to_your_file)
This should work in both CS4 and CS5.

Re: including external text file in an expression

Posted: October 18th, 2011, 10:29 pm
by MazingaZ
Hi there, I'm new here.
I hope there will be someone that will help me.
I need to copy a text from an external .txt file and assign it to source text. I've tried everything was possible I've find here and also the following expressions I've found over the web but no chance to work in CS5.5. Please do everybody have a solution?

1)

myPath = “file://c:\\\\Expressions\\”;
myPath += “data.txt”;
$.evalFile (myPath);
eval(thisComp.name);
}catch(err){“Not Found”}

2)

$.evalFile("c:\\\\Expressions\\text.txt"); eval(thisLayer.name);

3)

myPath = "/media/text.txt";
try{
$.evalFile (myPath);
eval(thisComp.name);
}catch (err){
"not found"
}



Thank you so much in advance,

Davide

Re: including external text file in an expression

Posted: October 19th, 2011, 1:21 pm
by Dan Ebberts
Try it this way:

$.evalFile("/c/Expressions/text.txt");

I tried it with a text.txt file containing this:

"test"

and it seems to work fine.


Dan

Re: including external text file in an expression

Posted: October 19th, 2011, 2:18 pm
by MazingaZ
Hi Dan,
thank you so much for your help!!!
It worked!!!!! Just a question how can I do if I have a text on multiple raws?
THANK YOU AGAIN!!!!!!!!!

Davide
Dan Ebberts wrote:Try it this way:

$.evalFile("/c/Expressions/text.txt");

I tried it with a text.txt file containing this:

"test"

and it seems to work fine.


Dan

Re: including external text file in an expression

Posted: October 19th, 2011, 2:36 pm
by Dan Ebberts
If I understand what you're asking, you just need to separate the text lines in your file with backslash+r, like this:

"Text Line 1\rText Line 2\rText Line 3"


Dan

Re: including external text file in an expression

Posted: October 19th, 2011, 2:49 pm
by MazingaZ
THIS IS EXACTLY WHAT I WANTED!!!!!!!!! THANK YOU SO MUCH DAN!!!!!!

Davide
Dan Ebberts wrote:If I understand what you're asking, you just need to separate the text lines in your file with backslash+r, like this:

"Text Line 1\rText Line 2\rText Line 3"


Dan