Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression error referencing a line of text that sometimes doesn’t exist

  • Expression error referencing a line of text that sometimes doesn’t exist

    Posted by Scott Mcgee on June 28, 2017 at 10:53 am

    This has come really handy at the moment

    txt = value;
    if (text.sourceText.length >= 50){
    for (i = 50; i > 0; i–)
    if (txt[i] == ” “) break;
    if (i > 0)
    txt.substr(0,i) + “\r” + txt.substr(i+1)
    else
    txt.substring(0,61) + “\r” + txt.substring(62,999);
    }else{
    txt
    }

    I use is alongside this

    mySplit = thisComp.layer(“Text”).text.sourceText.split(“\r”);
    mySplit[1];

    But I have text immediately below it, so I’ve included an additional part so it now looks like this.

    mySplit = thisComp.layer(“Programme Title”).text.sourceText.split(“\r”)
    mySplit[1];

    if (mySplit[1].length > 0) yPos = 176
    else yPos = 156;

    xPos = 410;

    [xPos,yPos]

    However this only work if there is text on the line, I thought that by adding “mySplit[1].length = 0”, but the line doesn’t officially exist until the text moves down to the next line.

    Would a try catch expression fix this?

    At the moment I’ve cheated it and and I get an expression error, but it still works. I just want it to be clean and not bring up the error.

    Scott Mcgee replied 9 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 28, 2017 at 1:12 pm

    Maybe like this:

    mySplit = thisComp.layer(“Programme Title”).text.sourceText.split(“\r”);
    if (mySplit.length > 1) mySplit[1] else “”;

    Dan

  • Scott Mcgee

    June 28, 2017 at 1:31 pm

    Was just about to say…solved it with a try catch, but yours worked as well after quickly trying it…I’m an idiot for not spotting and trying yours first.

    mySplit = thisComp.layer(“Programme Title”).text.sourceText.split(“\r”)
    try {mySplit[1]
    }catch(err){
    “”};

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