ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Read and print specific line from txt file - ExtendScript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Avinash Ramanath
Read and print specific line from txt file - ExtendScript
on Sep 20, 2018 at 3:02:54 pm

I'am trying to read only line 2 from a text file and print. How can I do it? Please help

If text file contains three line

this is line 1
this is line 2
this is line 3

I want to print only line 2. (or access any line i want)

my current code:

var dataFile = File("/Users/avinashramanath/Desktop/Content.txt");

dataFile.open("r");
var fields = dataFile.readln();

{
var comp = null;
for (var i=1; i&lt;=app.project.numItems; i++)
{
if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === "RenderComp"))
{
comp = app.project.item(i);
break;
}
}

if (comp === null)
{
alert("RenderComp does not exist");

}

comp.layer(1).property("Text").property("Source Text").setValue(fields);
}



Return to posts index

Dan Ebberts
Re: Read and print specific line from txt file - ExtendScript
on Sep 20, 2018 at 4:02:40 pm

I haven't tested this, but try replacing this line:

var fields = dataFile.readln();

With this:


var myLine = 2;

var fields;
for (var i = 1; i <= myLine; i++){
fields = dataFile.readln();
}



Dan



Return to posts index

Avinash Ramanath
Re: Read and print specific line from txt file - ExtendScript
on Sep 20, 2018 at 6:24:44 pm

Yes, Dan, this works perfectly. Many thanks.


Return to posts index

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