Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


split() - don't show 'undefined' text for blank data cell

Community Beginner ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

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)

i=**forLoop;

nameText = footage("Spreadsheet.csv").dataValue([0,i]);

nameText.split(" ")[0] + ['\n'] + nameText.split(" ")[1]

TOPICS
Expressions, Scripting

Views

103

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Mar 31, 2021 Mar 31, 2021
Something like this should work: nameText = footage("Spreadsheet.csv").dataValue([0,i]); nameSplit = nameText.split(" "); nameSplit.length > 1 ? nameSplit[0] + '\r' + nameSplit[1] : nameText

Likes

Translate

Translate
Guide ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Something like this should work:

 

nameText = footage("Spreadsheet.csv").dataValue([0,i]);
nameSplit = nameText.split(" ");
nameSplit.length > 1 ? nameSplit[0] + '\r' + nameSplit[1] : nameText

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

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?

Total beginner.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 01, 2021 Apr 01, 2021

Copy link to clipboard

Copied

I see.

It also seems to work indefinitely as well, repeating the break+split[newIndex] before the :

 

thanks Dan!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines