I have a script that needs to be tweaked very slightly. Right now this script is setup to save out files and rename them as follows:
current document file name + "-" + artboard name + (rename files from .ai to .pdf)
I need this script tweaked so that the exported file names are as follows:
artboard name + "-" + current document file name + (rename from .ai to .pdf)
Here's the script that needs to be tweaked:
#target illustrator
function artboardsToPDFs() {
if (app.documents.length = 0) {
return;
} else {
var docRef = app.activeDocument;
var docName = docRef.name;
var baseName = docName.replace(/.ai$/,'');
var dF = Folder(Folder.desktop + "/AI PDF's");
if (!dF.exists) dF.create();
var aB = docRef.artboards;
var autoNames = Array();
for (var i = 0; i < aB.length; i++) {
var abName = aB[i].name;
autoNames.push(baseName + '_' + abName + '.ai');
}
if (!docRef.saved) docRef.save();
var aiOpts = new IllustratorSaveOptions();
aiOpts.compatibility = Compatibility.ILLUSTRATOR13;
aiOpts.pdfCompatible = true;
aiOpts.saveMultipleArtboards = true;
var saveFile = File(dF.fsName + '/' + docName);
docRef.saveAs(saveFile, aiOpts);
docRef.close(SaveOptions.DONOTSAVECHANGES);
saveFile.remove();
renameFiles(dF, autoNames);
}
}
artboardsToPDFs();
function renameFiles(dir, fL) {
for (var i = 0; i < fL.length; i++) {
var f = File(dir.fsName + '/' + fL[i]);
if (f.exists) {
var reName = f.name.replace('_','-');
f.rename(reName);
f = File(dir.fsName + '/' + reName);
reName = f.name.replace(/\.ai$/,'.pdf');
t = File(dir.fsName + '/' + reName);
if (t.exists) t.remove();
f.rename(reName);
}
}
}
I thought so too, but that didn’t work, unfortunately. When only making that modification I get:
Re: Modify a script help? + “_” Re: Modify a script help? + .ai
So it doesn’t reorder the filename, doesn’t change the “_” to “-“, and doesn’t change the file name from “.ai” to “.pdf”
Thoughts?
This should do you… I updated it a touch… And made it simpler to edit… ![]()
#target illustrator
artboardsToPDFs();
function artboardsToPDFs() {
if ( app.documents.length == 0 ) { return; }
var aiOpts, artBds, baseName, doc, fileDef, fileRep, i, names, obj, saveFile, saveFold;
doc = app.activeDocument;
baseName = doc.name.replace( /.ai$/,'' );
saveFold = Folder( Folder.desktop + "/AI PDF's" );
if ( ! saveFold.exists ) { saveFold.create(); }
artBds = doc.artboards;
names = Array();
for ( i = 0; i < artBds.length; i++ ) {
obj = Object();
obj.defaultName = baseName + '_' + artBds[i].name + '.ai'; // Default AI naming convention
obj.replaceName = artBds[i].name + '-' + baseName + '.pdf'; // Script swap about
names.push( obj );
};
if ( ! doc.saved ) { doc.save(); }
aiOpts = new IllustratorSaveOptions();
aiOpts.compatibility = Compatibility.ILLUSTRATOR13;
aiOpts.pdfCompatible = true;
aiOpts.saveMultipleArtboards = true;
saveFile = File( saveFold + '/' + doc.name );
doc.saveAs( saveFile, aiOpts );
doc.close( SaveOptions.DONOTSAVECHANGES );
saveFile.remove();
for ( i = 0; i < names.length; i++ ) {
fileDef = File( saveFold + '/' + names[i].defaultName );
if ( fileDef.exists ) {
fileRep = File( saveFold + '/' + names[i].replaceName );
if ( fileRep.exists ) { fileRep.remove(); }
fileDef.rename( names[i].replaceName );
};
};
};
North America
Europe, Middle East and Africa
Asia Pacific