Hi,
I'm very new to JavaScript and I've combinded a few codes I've found on here to build a swatch color replacement tool. It works great! The only issue I'm having is that it only runs on one file in the selected folder. I would like it to run on all of the files in the folder. Am I missing a loop function? Any help appreciated very much. Thanks.
// Main Code [Execution of script begins here]
// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;
// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator');
// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
{
// Get the destination to save the files
//destFolder = Folder.selectDialog( 'Select the folder where you want to save files.', '~' );
destFolder = sourceFolder;
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files[i]); // returns the document object
app.paste()
app.cut()
var docRef = sourceDoc;
with (docRef) {
var replaceColor1= swatches.getByName('YELLOW Final').color;
for (var i = 0; i < pathItems.length; i++) {
with (pathItems[i]) {
if (filled == true && fillColor instanceof SpotColor) {
if (fillColor.spot.name == 'Yellow TEMP') fillColor = replaceColor1;
}
if (stroked == true && strokeColor instanceof SpotColor) {
if (strokeColor.spot.name == 'Yellow TEMP') strokeColor = replaceColor1;
}
}
}
for (var j = 0; j < stories.length; j++) {
with (stories[j]) {
for (var k = 0; k < characters.length; k++) {
with (characters[k].characterAttributes) {
if (fillColor instanceof SpotColor) {
if (fillColor.spot.name == 'Yellow TEMP') fillColor = replaceColor1;
}
if (strokeColor instanceof SpotColor) {
if (strokeColor.spot.name == 'Yellow TEMP') strokeColor = replaceColor1;
}
}
}
}
}
}
sourceDoc.save();
sourceDoc.close();
}
}
}
else
{
alert( 'No matching files found' );
}