Skip to main content
Known Participant
April 18, 2019
Answered

Batch Saving a single file

  • April 18, 2019
  • 4 replies
  • 3883 views

Complete scripting beginner here, I've done some research on this but cant get it to work quite right.

So I basically have a Master Illustrator file which has one A4 art board which has a back and front view of a t shirt plus other customer information, and then two smaller artboards which are overlaid, one around the front view, and one around the back view of the t shirt.

So I essentially need to export a load of different file from this master file, that I currently do manually, adding certain suffixes after each file. Ive tried to fudge it with Actions but it seems limited in terms of saving locations etc.

I need to:

-Save the Master File

-Export a PDF of the large artboard containing all information giving it the suffix _ProductionWorksheet

-Export one of the smaller artboard as a JPG with the suffix _FrontView

-Export the other smaller artboard as a JPG with the suffix _BackView

Id like to create a template file that does all this and place it in a folder - so i can then copy paste that folder for any new clients, rename it, and basically have a one button self save/updater.

I have tried to do this but the saving seems to all happen in the original file location and wont change to do it inside wherever the Master file is stored.

If anyone could help that would be a great help, as I'm currently doing all this manually and takes some time.

This topic has been closed for replies.
Correct answer Stephen Marsh

This is great - the hard coding of _ProductionWorksheet isn't an issue because the master files are always set up in the same manor.


Here is an updated version, using the artboard name rather than hard coding the text in:

// https://forums.adobe.com/thread/2615190

// Save the active .ai file and create a PDF file of artboard 1 and JPG files of artboards 2 & 3

#target illustrator

// Make Illustrator the frontmost application in case we double clicked the file

// app.bringToFront();

// https://forums.adobe.com/message/10703953#10703953

// The active document

var doc = app.activeDocument;

// The path of the original document

var originalDocPath = doc.path;

// The name of the original document

var originalDocName = doc.name;

// Get just the file name, ignore the file extension

// originalDocName = originalDocName.replace(/\.[^\.]+$, ""/)

var originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")

var ab1Name = doc.artboards[0].name;

var ab2Name = doc.artboards[1].name;

var ab3Name = doc.artboards[2].name;

// Setup pdf save options

var opts = new PDFSaveOptions();

opts.preserveEditability = false; // hack to restrict artboard  & reduce file size of final PDF

opts.artboardRange = "1";

opts.pDFPreset = "[Illustrator Default]";

// Save the document in the original folder using the original name as a PDF with _ProductionWorksheet

doc.saveAs(File(originalDocPath + "/" + originalDocName + "_" + ab1Name + ".pdf"), opts);

// Now export out JPEG files of artboards 2 & 3

// Possible sources of code:

// https://forums.adobe.com/message/10882995#10882995

// https://forums.adobe.com/message/9462145#9462145

// https://forums.adobe.com/message/10832229#10832229

var resolution = 300;

var artboard2 = 1;

var artboard3 = 2;

var dest1 = originalDocPath + "/" + originalDocName + "_" + ab2Name

var dest2 = originalDocPath + "/" + originalDocName + "_" + ab3Name

exportFileToJPEG1 (dest1, resolution, artboard2);

  

function exportFileToJPEG1 (dest1, resolution, artboard2) {

    var doc = app.activeDocument;

    doc.artboards.setActiveArtboardIndex(artboard2);

    var exportOptions = new ExportOptionsJPEG();

    var type = ExportType.JPEG;

    var fileSpec = new File(dest1);

    exportOptions.antiAliasing = true;

    exportOptions.artBoardClipping = true;

    exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size,

    exportOptions.verticalScale = resolution*100/72;

    exportOptions.qualitySetting = 100;

    app.activeDocument.exportFile( fileSpec, type, exportOptions );

}

exportFileToJPEG2 (dest2, resolution, artboard3);

  

function exportFileToJPEG2 (dest2, resolution, artboard3) {

    var doc = app.activeDocument;

    doc.artboards.setActiveArtboardIndex(artboard3);

    var exportOptions = new ExportOptionsJPEG();

    var type = ExportType.JPEG;

    var fileSpec = new File(dest2);

    exportOptions.antiAliasing = true;

    exportOptions.artBoardClipping = true;

    exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size,

    exportOptions.verticalScale = resolution*100/72;

    exportOptions.qualitySetting = 100;

    app.activeDocument.exportFile( fileSpec, type, exportOptions );

}

// Run the menu command

// app.executeMenuCommand('save');

// Or use the DOM code instead

app.activeDocument.save();

// Optionally close the original doc

app.activeDocument.close();

// Completed Notice

alert("Script Completed!" + "\n" + "Master .ai file saved. Production Worksheet .pdf file and Front/Back View .jpg files created.");

4 replies

Stephen Marsh
Community Expert
Community Expert
April 25, 2019

Cross posted here:

Automating File Export

Known Participant
April 24, 2019

OK I've got something working, seems to do the trick, albeit a little messy i guess. Can anyone see any streamline improvements i could make?

var activeDocument = app.activeDocument;

activeDocument.save;

var aiFile = activeDocument.fullName;

var jpegFolder = Folder(app.activeDocument.path);

       

for (var j = 0; j < activeDocument.artboards.length; j++) {

    var activeArtboard = activeDocument.artboards;

    activeDocument.artboards.setActiveArtboardIndex(j);

    var bounds = activeArtboard.artboardRect;

    var left = bounds[0];

    var top = bounds[1];

    var right = bounds[2];

    var bottom = bounds[3];

    var width = right - left;

    var height = top - bottom;

    if (app.activeDocument.rulerUnits == RulerUnits.Points) { //Add more if for more conversions

        width = width / 72;

        height = height / 72;

    }

    var fileSuffix = ["_ProductionWorksheet.pdf", "_FrontView.jpg", "_BackView.jpg" ];

    var fileName = activeDocument.name.split('.')[0] + fileSuffix;

    var destinationFile = File(jpegFolder + "/" + fileName);

    var type = null;

    if(j != 0){       

        type = ExportType.JPEG;

        var options = new ExportOptionsJPEG();

        options.antiAliasing = true;

        options.artBoardClipping = true;

        options.optimization = true;

        options.qualitySetting = 100; // Set Quality Setting

        activeDocument.exportFile(destinationFile, type, options);

        activeDocument.close();

        app.open(File (aiFile));

    } else if (j == 0){       

        var options = new PDFSaveOptions();

        options.compatibility = PDFCompatibility.ACROBAT5;

        options.generateThumbnails = true;

        options.preserveEditability = false;

        activeDocument.saveAs(destinationFile, options);

        activeDocument.close();

        app.open(File (aiFile));

    }

}

Disposition_Dev
Legend
April 19, 2019

can you share the script you're already using? it sounds like you have some file paths hard coded instead of determining them dynamically.

Known Participant
April 23, 2019

Ive been using actions, not script as ive got no scripting experience.

Stephen Marsh
Community Expert
Community Expert
April 19, 2019

I’m just a scripting newb, so my questions are more to get the ball rolling than anything else...

Are the artboards always in a consistent order, such as:

Production Work Sheet is always artboard #1

Front View is always artboard #2

Back View is always artboard #3

-Save the Master File

Would this file be previously saved in the correct location for the current project, or would it be an unsaved file requiring you to first navigate and save?

-Export a PDF of the large artboard containing all information giving it the suffix _ProductionWorksheet

-Export one of the smaller artboard as a JPG with the suffix _FrontView

-Export the other smaller artboard as a JPG with the suffix _BackView

What PDF preset would you be using?

What are the raster file requirements?

Known Participant
April 23, 2019

-Yes i will have the artboads set up and named as you show above

-This would be saving over the file opened, not saving a new version of it

-Standard illustrator presets for a PDF.

-Standard Illustrator Presets for RGB JPG's. (10 quality, 300ppi) This will be used as a product image on a website.

So

Template Customer

-FileName.AI (Save this file)

-FileName_ProductionWorksheet.PDF (Export this file, if one already exists of the same name save over it)

-FileName_FrontView.JPG (Export this file, if one already exists of the same name save over it)

-FileName_BackView.JP (Export this file, if one already exists of the same name save over it)

Ive managed to get this working in Actions, but its limited in terms of where it saves, and saving over existing files. When create a duplicate for a new customer and replay the Action, it will save all the file back into the original template file and just save extra ones called FileName_FrontView copy .jpg, copy 1, copy 2 etc. I need the exported files to follow its own master files location, and save out into the copied file structure and not the original one.

I dont mind the little "do you want to save over this file" popping up for each file, but if that could be avoided that would be ideal.

Im really in too deep when i comes to coding. And cant find any tutorials that even instruct you on how to do anything like this.

Actions seems too basic for what im trying to achieve.

Stephen Marsh
Community Expert
Community Expert
April 23, 2019

The following may not be THE answer - but it may be AN answer...

Use the action panel menu and select Batch. select the input folder.

Select the action set and action. Check the override save and override export options and set new output folder locations.

What do you get?