ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

CSV with linebreaks for source text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Gary Frewin
CSV with linebreaks for source text
on Jan 2, 2019 at 1:11:54 pm
Last Edited By Gary Frewin on Jan 2, 2019 at 2:40:28 pm

Hi All,

I'm creating a template wherein a beginner user can import a csv to populate textboxes (and highlight certain words using the awesome expression in this post). But I'm now stuck at the csv part.

I've imported a csv with four columns: ID, Text, Highlights, and Visual
The text layer inside the composition will use the composition name to reference the desired row and set the sourceText using the following expression:

var compIndex = thisComp.name;
var textField = footage("TOVDataTest.csv").dataValue([1,compIndex]);
textField;


this works perfectly, until... I try to include line breaks in my csv file.

It's essential that the user can control where line breaks are inserted.

When I use alt+enter to create line breaks in cells in my CSV (through excel), it throws in the row/column references off, and the compIndex starts returning data from other columns.

Any solutions/ideas would be really appreciated

Many thanks
Gary


Return to posts index

Gary Frewin
Re: CSV with linebreaks for source text
on Jan 2, 2019 at 3:31:28 pm

Ok, I have solved this it seems (by some miracle as I'm a pretty bad coder!). There are likely more elegant solutions, but here's what I did:


var compIndex = thisComp.name.split(" - ")[0];
var textField = footage("TOVDataTest.csv").dataValue([1,compIndex]);
var thisText = ""
for (i = 0; i < textField.split("@@").length; i++){
thisText += textField.split("@@")[i] + "\n";
}


The solution was to forget about line breaks in the csv and use the split method array and a for loop with \n to create the lines.

Now the users simply duplicates the master template, names them all numerically, and the data is pulled in from the CSV.


Return to posts index

Gary Frewin
Re: CSV with linebreaks for source text
on Jan 5, 2019 at 12:25:22 pm

A further development.

In trying to import the text from the CSV, I've noticed some strange behaviour. Any help resolving them would be much appreciated.

If the user has included an apostrophe when creating the CSV (for example in It's) no characters following the apostrophe are displayed in the textboxes when the CSV is first imported to the AFX project... however, if the user deletes the apostrophe, saves the cs, and let's AFX refresh, then reinserts the apostrophe, when afx refreshes again the error goes away and the full sentence is displayed.

If the user tries to add an ellipsis in the csv (...) it doesn't display at all, no matter what they do.

thoughts/solutions/workarounds?

Thanks
Gary


Return to posts index


Bouke Vahl
Re: CSV with linebreaks for source text
on Jan 5, 2019 at 1:25:04 pm

Hi Gary,
I know NOTHING about AE expressions, but I do know (a bit) about coding.

Try DuckDuckGoing for 'escape CSV characters'

Some characters have 'meaning' other than being text.
Escaping is a way to let the environment know that the character in question is in fact a character, instead of a command or code or something. (eg, you put in another quote before the quote char, or something like that.)
I bet with a search / replace of your CSV text you can fix this.

Bouke
http://www.videotoolshed.com


Return to posts index

Gary Frewin
Re: CSV with linebreaks for source text
on Jan 7, 2019 at 8:58:01 am

Hi Bouke,

Thanks for this, it helped me to solve it. Fortunately it required no extra coding or characters that would confuse the end-user. While searching for escape characters I stumbled on a stack overflow article that talked about UTF formatting on a csv.

All I had to do was go into excel and change the 'save as' file format from normal csv, to csv utf-8



Works perfectly now!
Thanks!


Return to posts index

Bouke Vahl
Re: CSV with linebreaks for source text
on Jan 7, 2019 at 9:40:29 am

Ah, good.
But, out of curiosity, how does the script handles a comma in your regular text, if you have a comma separated input?
(I would think that could cause mayhem...)

Bouke
http://www.videotoolshed.com


Return to posts index


Gary Frewin
Re: CSV with linebreaks for source text
on Jan 7, 2019 at 1:00:51 pm

Hi Bouke,

It seems to work fine, I just tried a cell made up entirely of commas... all displayed fine. ☺

Thanks,
Gary


Return to posts index

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