We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
I'm an animator working with JS in AE expressions and I have to make dynamic charts with CSV data controlling points and values. That's all going fine, but what I'm stuck on is that some name value are two words, some are single, and I need to break up the double words onto two lines. When I do it the way I found, the single words display as the word on the first line, and the word 'undefined' on the second line. Obviously because there isn't a second value.
Is there a better way to script the line break so there isn't an undefined value? It needs to be flexible for one or two words in either cell.
Here's the code I have so far :
(I've simplified the for loop cos it linked to other layer names)
nameText = footage("Spreadsheet.csv").dataValue([0,i]);
nameText.split(" ") + ['\n'] + nameText.split(" ")
Something like this should work:
nameText = footage("Spreadsheet.csv").dataValue([0,i]); nameSplit = nameText.split(" "); nameSplit.length > 1 ? nameSplit + '\r' + nameSplit : nameText
That worked perfectly! thank you so much.
I think I understand the last line, except the ': nameText'
Does that say that the splits are part of the same item?
No, that's the else part of the conditional operator (?). If the split text isn't longer than one element, it just uses the original text.
It also seems to work indefinitely as well, repeating the break+split[newIndex] before the :
Copy link to clipboard
Great that Dan already provided a solution!
Extra Tip: For dynamic graphs based on spreadsheet data, the chapter Tempaltes & Automation of my free eBook Motion Graphics in After Effects that Speaks to Your Brain also contains a lot of helpful infos.