• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
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

444

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

Community Expert , 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

Votes

Translate

Translate
Community Expert ,
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

Votes

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
Explorer ,
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.

Votes

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 Expert ,
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.

Votes

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
Explorer ,
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!

Votes

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 Expert ,
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.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

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