forked from matsilva/aetextio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaetextin - Current Comp.jsx
46 lines (38 loc) · 1.51 KB
/
aetextin - Current Comp.jsx
1
{ app.beginUndoGroup("Import csv text file"); // create undo group var TextIn = new Object; TextIn.allText = new Array; //Get all text layers and replace their source with corresponding value in array TextIn.replaceText = function(textArray){ var b=0; app.activeViewer.setActive(); var activeComp = app.project.activeItem; if (app.project.item(i) instanceof CompItem) { for (var j = 1; j <= activeComp.layers.length ; j++) { if(activeComp.layer(j) instanceof TextLayer){ $.write(activeComp.layer(j).name); activeComp.layer(j).text.sourceText.setValue(textArray[b]); b++; } } } }; //Get text file, read it, then split csv into global array TextIn.getFile = function(callback){ var textFile = File.openDialog("Please select input text file."); if (textFile != null){ textFile.open("r"); // open file } var text; while (!textFile.eof){ text = textFile.readln(); if (text == "") text = "\r" ; } TextIn.allText =text.replace(/([^\\]),/g, '$1\u000B').replace(/\\(,)/g, '$1').split('\u000B'); writeLn(TextIn.allText.toString()); textFile.close(); callback(TextIn.allText); }; TextIn.getFile(TextIn.replaceText); //Execute script app.endUndoGroup();}