FORUMS: list search recent posts

Source Text from Text File

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mark Walczak
Source Text from Text File
on Mar 18, 2010 at 9:30:03 pm

Hi everyone,

So, I realize that this topic has been discusses at great length on several forums (including the Cow), but I have been searching tirelessly and without success for my own application. Here's what I'm trying to do:

Feed a text layer a text file and have it sample one word from the document for every frame of video.

I realize that many types of "text file to AE" questions deal with lower thirds, and generating comps, but this isn't quite what I'm going for. I should mention that I'm on a Mac, in case that makes any difference, and I am running AE CS4.

Thank you in advance!

http://vimeo.com/explosivegraffix


Return to posts index


cowcowcowcowcow
Dan Ebberts
Re: Source Text from Text File
on Mar 18, 2010 at 11:00:08 pm

With this text file:

txt = "one two three four five six seven eight nine ten";

This expression displays a different word on each frame:

myPath = "/C/Temp/text_test.txt";
try{
$.evalFile (myPath);
mySplit = txt.split(" ");
f = timeToFrames()
mySplit[Math.min(f,mySplit.length-1)]
}catch (err){
"file not found"
}

Of course your file path will be different, and you may want to use something other than spaces to delimit your words. This works for CS4 -- if you have CS3 you'll have to use the #include method.

Dan



Return to posts index

Mark Walczak
Re: Source Text from Text File
on Mar 19, 2010 at 2:00:47 pm

Dan, you are my hero!

Thanks again for another amazing expression!

http://vimeo.com/explosivegraffix


Return to posts index


Brian Byrne
Re: Source Text from Text File
on Apr 18, 2010 at 11:12:06 pm

I have a .txt file with almost 1800 names (first and last) separated by a line break. I'd like to split all names up into single frames of one text layer for use as a sprite in Particular 2.0. I'm able to use what you have here as a good starting point, but I'm afraid I don't know enough about expressions. I'll keep crunching through the expressions documentation, but if anyone can provide suggestions it would be greatly appreciated.


Return to posts index

Dan Ebberts
Re: Source Text from Text File
on Apr 19, 2010 at 3:00:27 am

In my opinion, you'd be much better off using a script for this. The script would read each line of the text file and create a new keyframed value for the source text at each frame.

Alternatively, to get the expression to work, you'd have to alter your text file so that each line is a valid expression statement, like this:

txt = [];
txt[0] = "your first word";
txt[1] = "your second word";

etc.

Then you could use a source text expression that assigns a new word at each frame. like this (not tested):

myPath = "/C/Temp/text_test.txt";
$.evalFile (myPath);
f = timeToFrames();
txt[Math.min(f,txt.length-1)]

At each frame, the expression has to read in the enitire 1800 line text file. If you use a script rather than the expression, you only have to read the text file once. Of course, it's a bit of work to create such a script.


Dan




Return to posts index

Tom Granberg
Re: Source Text from Text File
on May 12, 2010 at 8:30:34 pm

Hi Dan

I am using Cs3, windows, and obviously this expression doesnt quiete work.
What changes to the expression do I need?

Path = "I:code01.txt";
try{
$.evalFile (Path);
eval(Textflow);
}catch (err){
"not found"
}


Return to posts index


Dan Ebberts
Re: Source Text from Text File
on May 12, 2010 at 10:21:58 pm

CS3 is going to need something like this for the first line:

#include '/I/code01.txt';

Beyond that, it's hard to say without knowing what's in the text file and what you're trying to do.


Dan



Return to posts index

Tom Granberg
Re: Source Text from Text File
on May 12, 2010 at 11:51:14 pm

Just trying to get a text layer to accept a txt file.
Do I need some formatting on the slashes?

#include '//I//code01.txt';

I running win7

Thank you so much.

T


Return to posts index

Dan Ebberts
Re: Source Text from Text File
on May 13, 2010 at 2:16:23 am

The text layer has to contain executable javascript statements. For example if I have a text file (named "text_test.txt" on my c drive in the temp folder) containing this text:

txt = "one two three four five six seven eight nine ten";

I can add this expression (CS3) to a text layer:

#include '/C/temp/text_test.txt'
txt

and the text layer will display this:

one two three four five six seven eight nine ten

I hope that helps.

Dan



Return to posts index


Tom Granberg
Re: Source Text from Text File
on May 13, 2010 at 8:17:58 pm

I wish it worked, I am sure it does on Mac platforms.
I cant for the world of me get it to work, I keep getting file/folder not found errors.

I am using win7 with CS3 if that helps.
My path is as follows:
C:\Users\Renderbrandt\Documents\text\doce01.txt

Is there a special way I need to format the path?

Thanks iun advance, I wish I wasnt shuch an pia...

Tom aka Renderbrandt


Return to posts index

Dan Ebberts
Re: Source Text from Text File
on May 13, 2010 at 9:00:35 pm

Please try:

/C/Users/Renderbrandt/Documents/text/doce01.txt


Dan




Return to posts index

Tom Granberg
Re: Source Text from Text File
on May 13, 2010 at 9:09:17 pm

You are such a sport Dan!
At least now I do not get an error on the path, so I assume that is correct now.

However I do get this now, I tried to add ";" but that seems to not work.

After effects warning: Expected: ;
Error occurred at line 3.


Using this:

#include '/C/Users/Renderbrandt/Documents/text/code01.txt';


Return to posts index


Dan Ebberts
Re: Source Text from Text File
on May 13, 2010 at 9:18:44 pm

1. What's the entire text of your expression?

2. What's in your text file (exactly)?

Dan



Return to posts index

Tom Granberg
Re: Source Text from Text File
on May 13, 2010 at 9:24:32 pm

First, thank you so much Dan for taking your time.

All I want is to show the text from the .txt file, not read the text as code, just plain text.

The entire expression is:
#include '/C/Users/Renderbrandt/Documents/text/code01.txt';

I was going to to try "hack" an expression to show random lines of the text file too. But one step at the time I suppose.

The text itself is actual a random code dump, I am using it as "generic" text for a computer screen on set.

Again thank you for teaching me this.

T


Return to posts index

Dan Ebberts
Re: Source Text from Text File
on May 13, 2010 at 9:33:53 pm

The file is going to get interpreted as JavaScript code, not text, so the file has to consist of valid javascript statements. The best you can do is probably put something like this in the text file:

txt1 = "first line of text";
txt2 = "second line of text";
txt3 = "third line of text";
etc.

Then in your expression you would have some code that would randomly display txt1, txt2, or txt3, etc.

Dan





Return to posts index


Tom Granberg
Re: Source Text from Text File
on May 13, 2010 at 9:37:41 pm

Aha, Now I do understand!!!
I wasnt aware that the file itself would be read as javascript.

wow, I feel so......dumb


T


Return to posts index

peter auboeck
Re: Source Text from Text File
on Jan 27, 2011 at 2:18:35 am

he guys

this expression works great for windows., but i tried it with a mac an afx cs5 and it does not work at all !!! what could be wrong? i think there is a problem with the correct path. the file is on " home" so teh path should be /text_test.txt but it isn`t

can anybody help me

thanx petee


Return to posts index

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