help needed! Illustrator - script importing csv file _ txt file with unicode (u+1234)
- March 9, 2022
- 2 replies
- 2752 views
hi there,
appriciate your help:
## scenario
finally the script will import data from a csv file (basicly it is a txt file in my case, separated by tabs and returns) into an array (split, separate,nested) to change existing fonts and for some of them unicode based characters as well.
## question
how can I get those unicodes (u+1234) imported from that list in a propper way into that array so I can use them to search and replace others?
## already tried
if the array is manualy written it works fine -- I do need to get the unicode imported
already searched and tried for three days now... so please will you help me out?
find the txt and a demo ai-file attached ! ! ! rename attached .pdf ---> .ai to open in Illustrator ! ! ! ...
correct font or correct unicode numbers are not important (it just has to workout to switch existing ones)
script:
----------------------------
#target illustrator
//// ##### ----->>> This array is suposed to be imported from a csv/txt list
var array0 = [];
array0.push('PoloCEF-Regular');
array0.push('PoloST11K');
var array1 = [];
array1.push('Swift');
array1.push('Sally');
var array2 = [];
array2.push('MyriadPro-Regular');
array2.push('ArialMT');
array2.push('\u2030'); //unicode import does not work
array2.push('\u0023'); //unicode import does not work
var array3 = [];
array3.push('ZapfDingbatsITC');
array3.push('ArialMT');
array3.push('\u2794'); //unicode import does not work
array3.push('\u0023'); //unicode import does not work
var splittedRows = [];
splittedRows.push(array0);
splittedRows.push(array1);
splittedRows.push(array2);
splittedRows.push(array3);
//// ##### ----->>>
var docRef = app.activeDocument;
var allTextFrames = docRef.textFrames;
var autoSubList = ['PoloST11K','SomeFont','Swift','ArialMT','ZapfDingbatsITC','MyriadPro-Regular']
//// ##### ----->>>
changeFontAndGlyphs();
alert("done");
// get list of used fonts based on characters
function changeFontAndGlyphs() {
for (var i=0 ; i<allTextFrames.length; i++) { // check all text frames
var allCharacters = allTextFrames[i].characters; // get all characters of this frame
for (var t=0; t<allCharacters.length; t++) { // check all characters
var charFontName = allCharacters[t].textFont.name; // get font name of this character
var thisChar = allCharacters[t]; // get this one character
for (var c=0; c<splittedRows.length; c++) { // check all rows of changelist
var thisCLFont = splittedRows[c][0]; // get 1st of ChangeList array = font for change
var newCLFont = splittedRows[c][1]; // get 2nd of ChangeList array = sub font to be changed to
for (var a=0; a<autoSubList.length; a++) { // check all fonts of autoSubList
var thisASLFont = autoSubList[a]; // get this AutoSubListFont
if (thisASLFont == thisCLFont && charFontName == thisCLFont) {
// if AutoSubList font is on changeListFont && character font has same name as changeListFont
thisChar.textFont = app.textFonts.getByName(newCLFont); //change character font to new changeList font
if (splittedRows[c].length > 2) { // changelist row >2 ==> has Glyphs to change
thisUcode = splittedRows[c][2];
newUcode = splittedRows[c][3];
myUniCode = thisChar.contents;
thisChar.contents = replaceUniCode(myUniCode);
} else {}
} else {}
}
}
}
}
}
function replaceUniCode() {
myUniCode = myUniCode.replace( thisUcode, newUcode );
return myUniCode;
}
-------------- End of Script
Textfile looks like this (tab separated):

