Copy link to clipboard
Copied
My script takes a TSV file of messages, writes XML files for each one, then imports those in as variables on a template file, save pdf, rinse and repeat.
The script works fine when run from vscode but I can't get it to work when running from illustrators scripts folder. The XML files generated aren't encoded correctly or "Text encoding Unicode (UTF-8) isn’t applicable." as Finder puts it. The files that fail are ones with characters like right quote marks or an é.
The script should regex these out before writing the XML file and it does: from vscode. But not when run from illustrator. And I'm losing my mind trying to find out why. Link to github repo of script and test files: https://github.com/MitchPope/AddMessageToCard.git
Hmmm do any of those special characters do something to spoil the XML? I just used UTF-8 as file encoding, when you open a file for writing, (set the encoding to "UTF-8") and I was able to use just the replacing of strings which are not XML-valid:
function disguiseXmlEntities(str){
str=str.toString();
str=str.replace(/&(?!(amp;|gt;|lt;|quot;|apos;))/g, "_#_amp_#_");
str=str.replace(/</g, "_#_lt_#_");
str=str.replace(/>/g, "_#_gt_#_");
str=str.replace(/'/g, "_#_apos_#_");
str=str.re
...
Copy link to clipboard
Copied
Hmmm do any of those special characters do something to spoil the XML? I just used UTF-8 as file encoding, when you open a file for writing, (set the encoding to "UTF-8") and I was able to use just the replacing of strings which are not XML-valid:
function disguiseXmlEntities(str){
str=str.toString();
str=str.replace(/&(?!(amp;|gt;|lt;|quot;|apos;))/g, "_#_amp_#_");
str=str.replace(/</g, "_#_lt_#_");
str=str.replace(/>/g, "_#_gt_#_");
str=str.replace(/'/g, "_#_apos_#_");
str=str.replace(/"/g, "_#_quot_#_");
return str;
};
function undisguiseXmlEntities(str){
str=str.toString();
str=str.replace(/_#_amp_#_/g, "&");
str=str.replace(/_#_lt_#_/g, "<");
str=str.replace(/_#_gt_#_/g, ">");
str=str.replace(/_#_apos_#_/g, "'");
str=str.replace(/_#_quot_#_/g, """);
return str;
};
So far as I know, this has worked out for users across the world in many different languages with special characters. Maybe something else is at play due to your script running in different ways from VSCode as compared to Illustrator.
Also out of curiosity, is there some reasons why in your workflow it's necessary to use the datasets instead of simple scripting methods to set the text of text frames? I'm curious because it's a lot more work to do this compared to the latter and there may be some interesting reasons why this is preferred and I'd like to know those!
Copy link to clipboard
Copied
I still have no idea what the root cause was and I never will because the second part of your reply made me reassess my aproach. It wasn't necassary to use datasets, I was just re-using code from another more complicated project.
I just rewrote the script to change the text directly without an xml inbeween and illustrator seems ot just deal with any special characters. Thanks for your reply, I'd forgot there's more than one way to do things! Updated the repo if anyone comes across this and needs it.