ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Expression error referencing a line of text that sometimes doesn't exist
on Jun 28, 2017 at 10:53:52 am
Last Edited By Scott McGee on Jun 28, 2017 at 10:54:07 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.


Return to posts index

Dan Ebberts
Re: Expression error referencing a line of text that sometimes doesn't exist
on Jun 28, 2017 at 1:12:02 pm

Maybe like this:

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



Dan



Return to posts index

Scott McGee
Re: Expression error referencing a line of text that sometimes doesn't exist
on Jun 28, 2017 at 1:31:59 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){
""};


Return to posts index

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