Hi, I'm new to scripting and I think I've bitten off more than I can chew and I was wondering if someone can help clean up the mess I've created. I'm trying to write a script that will do the following: Ask me for an export location on my drive Ask me at what resolution I would like to export my artboards (for the jpeg exports). Then, save any artboard that has the name LAYOUT in it to a single PDF with the [Smallest File Size] setting. (So if there were three artboard that had LAYOUT in the artboard name, I'd end up with three separate PDFs, each with ONLY one of the designated artboards). Save any artboard that does NOT have LAYOUT in the artboard name as a jpeg at the full size of the artboard and at the resolution that was set in the step 2 dialogue. I would like all of the saved files to have the naming structure "NameOfCurrentDocument_ArtboardName.extension" Here is the script I've been messing with. It's making some of the exports, but coming up with weird file names, and the PDFs include all of the artboard and don't seem to be compressing down the the settings in [Smallest Files Size], and it's exporting the same artboard multiple jpegs instead of one artboard per jpeg. I'm guessing I've messed up a loop somewhere... Any help or guidance would be so very appreciated. // Define the target folder for the exported files
var exportFolder = Folder.selectDialog("Select a folder for export");
if (exportFolder != null) {
// Get the current document
var doc = app.activeDocument;
// Get the current file name
var fileName = doc.name.split(".")[0];
//returns the number of artboards in the document
var numArtboards = doc.artboards.length;
//set the restoultion of the export
var resolution = prompt("Please enter the resolution for export (in pixels per inch):");
// Loop through all artboards
for (var i = 0; i < numArtboards; i++) {
var artboard = doc.artboards[i];
var artboardName = artboard.name;
// Check if the artboard name includes "Layout"
if (artboardName.indexOf("LAYOUT") >= 0) {
// Save the artboard as PDF with the "Smallest File Size" preset
function saveAsPDF() {
var saveFile = new File(exportFolder + "/" + fileName + "_" + artboardName + ".pdf");
var pdfOptions = new PDFSaveOptions();
pdfOptions.artboardRange = artboard;
pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
pdfOptions.generateThumbnails = true;
pdfOptions.preserveEditability = false;
pdfOptions.preset = "[Smallest File Size]";
app.activeDocument.saveAs(saveFile, PDFSaveOptions);
}
saveAsPDF()
} else {
// Export the artboard as JPEG with the specified resolution
if (resolution != null) {
var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];
var options = new ImageCaptureOptions();
options.resolution = resolution;
options.artBoardClipping = true;
options.antiAliasing = true;
options.matte = false;
options.horizontalScale = 100;
options.verticalScale = 100;
options.transparency = true;
var destFile = new File(exportFolder + "/" + fileName + " " + artboardName + ".jpg");
doc.imageCapture(destFile, activeAB.artboardRect, options);
}
}
}
}
... View more