Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Read and print specific line from txt file – ExtendScript

  • Read and print specific line from txt file – ExtendScript

    Posted by Avinash Ramanath on September 20, 2018 at 3:02 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<=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);
    }

    Avinash Ramanath replied 6 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    September 20, 2018 at 4:02 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

  • Avinash Ramanath

    September 20, 2018 at 6:24 pm

    Yes, Dan, this works perfectly. Many thanks.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy