I am newbie in Illustrator Scripting.
I wrote a find replace script which looks for specific text in the file and replaces with some given content:
For Example: AI file has - 'I love my Dad' and we want to replace Dad with Mom, Uncle etc. using script. Current script works perfectly fine for simple text but if we add Style to part of text like 'I LOVE my DAD' - (Italic LOVE and Bold DAD) the replacement doesn't work...I expect it to be: 'I LOVE my MOM' but the result is - 'I LOVE my MOM' with all style removed.
Current Script |
---|
var pageItemRef = document.layers[0].pageItems[0] pageItemRef.contents = pageItemRef.contents.replace(replacementText, fileArray[i][1]); replacementText = fileArray[i][1];
var myDoc = app.activeDocument
for (s = 0; s < curStyles.length; s++) { var lastStyle = curStyles[ s ]; lastStyle.applyTo( document.textFrames[0] ); }
var options = new ExportOptionsPNG24(); var file = new File(folder + "/" + fileArray[i][0] + ".png"); document.exportFile(file,ExportType.PNG24,options);
var file2 = new File(folder + "/" + fileArray[i][0] + ".ai"); document.saveAs(file2); |
I am not sure if it's possible through script to retain the content styling.
Please can someone urgently suggest a workaround or point me to some article....