Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions reading text from a file

  • Filip Vandueren

    July 9, 2020 at 10:07 am

    Yes, the way you have this set up, the external file needs to be valid Javascript.
    in Javascript you need to escape quotes to use within a quoted string:


    myvalue= "myvalue is using \"these kinds of quotes\" even though it's delimited by double quotes";

    Furthermore, I thought $.evalFile() was officially not supported, but seems to work here.

  • Vasyl Iskovych

    July 9, 2020 at 11:15 am

    [Filip Vandueren] “using \”these kinds of quotes\””
    Thank you very much.
    You helped me a lot.
    [Filip Vandueren] “$.evalFile() was officially not supported”
    May I ask why this is not suitable?
    Can you advise another solution?
    I am not very experienced in this.
    I am trying to make a template for VideoHive.
    If this does not work or there are errors, then they will not accept it from me.

    I would like to ask one more question.
    Can I find out the number of lines in the text?
    I want to make the text align vertically if a new line is added to it.
    If I write the expression text.sourceText.length, then I get the number of characters.
    I would like to know the number of lines.
    Thank.

  • Vasyl Iskovych

    July 9, 2020 at 11:16 am

    [Filip Vandueren] “using \”these kinds of quotes\””
    Thank you very much.
    You helped me a lot.
    [Filip Vandueren] “$.evalFile() was officially not supported”
    May I ask why this is not suitable?
    Can you advise another solution?
    I am not very experienced in this.
    I am trying to make a template.
    If this does not work or there are errors, then they will not accept it from me.

    I would like to ask one more question.
    Can I find out the number of lines in the text?
    I want to make the text align vertically if a new line is added to it.
    If I write the expression text.sourceText.length, then I get the number of characters.
    I would like to know the number of lines.
    Thank.

  • Filip Vandueren

    July 9, 2020 at 12:17 pm

    on this page:
    https://helpx.adobe.com/be_nl/after-effects/using/legacy-and-extend-script-engine.html#main-pars_header_328857513

    it says it’s not supported, but the page may be out of Date,
    or it may be unsupported but work anyway ☺
    I can’t get it to work, but I am on Mac and maybe a different version of After Effects than you are.

    Alternatively:
    You can add .json or .csv files as footage inside of a project and get their sourcetext, sourceData, or JSON.parse() them.

    a txt.json file could look like this:

    {
    "text_1": "My first text \r has multiple \n lines",
    "text_2": "My second text \"using quotes\" "
    }

    If you make valid JSON-files, then there are methods to know how many members there are in the JSON object, like this:


    Object.keys(footage("txt.json").sourceData).length;

    if you want to know how many lines are in a string, you should count the number of \n or \r characters in it. My preferred method is like this:

    myString = =footage("txt.json").sourceData.text_1;
    lines = myString.split(/\r|\n/).length;

  • Filip Vandueren

    July 9, 2020 at 12:29 pm

    To better address your last question, you were asking about text that is already in sourceText:

    lines = text.sourceText.split(/\r|\n|\u0003/).length;

    notice I also check for Unicode character 0003, which is “end of text”, and is what After Effects uses for soft line breaks (shift-enter) that start a new line, but not a new Paragraph.

  • Vasyl Iskovych

    July 9, 2020 at 12:57 pm

    Thanks so much for your detailed answers.
    Please tell me why the \n character is used?
    I did not measure the difference if using \n or not using it.
    Unfortunately, I did not find information on the Internet.
    If possible, please tell me where to read about these values.
    Thank.

  • Filip Vandueren

    July 9, 2020 at 3:13 pm

    Just an old habit,

    line feed \n
    carriage return \r

    https://en.wikipedia.org/wiki/Newline#Issues_with_different_newline_formats

  • Vasyl Iskovych

    July 9, 2020 at 3:27 pm

    Thank you very much.
    You helped me a lot.
    But I want to ask more.
    Hope this will be the last question.
    I am trying to work with a .json file.
    But when, after I accidentally corrupt the file, I cannot resume its work, even after I fix the file.
    I tried to clear the memory, replace the footage, and even deleted and imported the file again. but he refuses to work.
    Please watch the video to better understand what I mean.
    And this does not always happen, but only sometimes.
    I recorded a video several times to catch this error.
    https://www.youtube.com/watch?v=7U6soc6_sRM

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Filip Vandueren

    July 9, 2020 at 3:35 pm

    Hmmm…
    I see, I can replicate the same problem.

    however:
    I never add the JSON to my timelines. If you have huge datasets, it takes superlong and a lot of memory to create all those properties in the timeline.

    I just get my data straight from the footage in the project-window wherever I need it.

    footage("txt.json").sourceData.text_1;

    If the source JSON breaks, the expression does give an error.
    When the file is fixed and refreshed; it immediately works again.

  • Vasyl Iskovych

    July 9, 2020 at 3:53 pm

    Thank you very much.
    I thought that if the data is not displayed on the timeline, then they will not work in the expression.
    I did not check it then.
    Now I checked it and it works.
    Thank you again.

Page 1 of 2

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