Activity › Forums › Adobe After Effects Expressions › Read and print specific line from txt file – ExtendScript
-
Read and print specific line from txt file – ExtendScript
-
Avinash Ramanath
September 20, 2018 at 3:02 pmI’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 3I 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<=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);
} -
Dan Ebberts
September 20, 2018 at 4:02 pmI 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
Reply to this Discussion! Login or Sign Up
Log in to reply.