Copy link to clipboard
Copied
Hi all, I've been using Illustrator scripts for years, but thought I would start trying to write some of my own to speed up repetitive tasks. I am trying to write a script that outlines all fonts and outputs a PDF and duplicate AI file. All is working well except my for loop seems to only working on every second text frame. The code below is the section in question. I would love to know if I am doing something wrong here or whether this is a bug. Any suggestions for better ways of doing this would also be appreciated.
var doc = activeDocument;
var frames = doc.textFrames;
for (i = 0; i < frames.length; ++i) {
frame = frames[i];
frame.createOutline();
}
Cheers,
Haniel
Hi Haniel, whenever you do something to an object that changes it dramatically—in this case you are destroying the textFrame, and replacing with a bunch of path items—the reference you have in frames variable now points to the wrong thing. It is still a reference to "the first textFrame in the document" but now that is the second text frame. So, when i == 0, the operation outlines textFrame 1; when i ==1, the operation outlines textFrame 3 (textFrame 2 is referenced in frame[0] now.
The easiest
...Copy link to clipboard
Copied
Hi Haniel, whenever you do something to an object that changes it dramatically—in this case you are destroying the textFrame, and replacing with a bunch of path items—the reference you have in frames variable now points to the wrong thing. It is still a reference to "the first textFrame in the document" but now that is the second text frame. So, when i == 0, the operation outlines textFrame 1; when i ==1, the operation outlines textFrame 3 (textFrame 2 is referenced in frame[0] now.
The easiest solution is to do the destructive operation backwards. The references still get messed up but they don't reshuffle all the others.
var doc = activeDocument;
var frames = doc.textFrames;
for (var i = frames.length - 1; i >= 0; i--) {
frames[i].createOutline();
}
- Mark
Copy link to clipboard
Copied
I forgot to add: good on you for having a go at your own script! That's awesome!
- Mark
Copy link to clipboard
Copied
Thanks for that Mark, makes perfect sense now that you explain it. Your suggestion worked a treat.
Here is my completed script for anyone else that might find it useful. It basically asks for a artwork/item code and issue/version number then creates a pdf and ai file named accordingly, with fonts converted to outlines and images imbedded (just how our production facility wants them).
// Set the active document
var doc = activeDocument;
// Get new Part and Issue information
var itemCode = prompt("Enter Item number","");
var newIssueNo = prompt("Insert new Issue Number","");
// Get location of active file
var location = doc.path;
// Compile output names
var artName = itemCode + " ISSUE " + newIssueNo + " ARTWORK";
var pdfName = itemCode + " ISSUE " + newIssueNo + " PROOF";
// Set Output Destinations
var artDest = location + "/" + artName;
var pdfDest = location + "/" + pdfName;
// Set save as AI file function
function exportFileToAI(dest) {
var ai24Doc = new File(dest);
var aiExportOpts = new IllustratorSaveOptions();
aiExportOpts.compatibility = Compatibility.ILLUSTRATOR24;
aiExportOpts.embedICCProfile = true;
aiExportOpts.embedLinkedFiles = true;
doc.saveAs(ai24Doc, aiExportOpts);
}
// Set save as PDF file function
function saveFileToPDF(dest) {
var pdfDoc = new File(dest);
pdfSaveOpts = new PDFSaveOptions();
pdfSaveOpts.compatibility = PDFCompatibility.ACROBAT5;
pdfSaveOpts.generateThumbnails = true;
pdfSaveOpts.preserveEditability = true;
doc.saveAs(pdfDoc, pdfSaveOpts);
}
//Save a low resolution PDF
saveFileToPDF(pdfDest);
// Convert all text to outlines
var frames = doc.textFrames;
for (var i = frames.length - 1; i >= 0; i--) {
frames[i].createOutline();
}
//Save as Ai File
exportFileToAI(artDest);
//Close file
doc.close();
Copy link to clipboard
Copied
Nice! Thanks for posting. 🙂
- Mark
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more