Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Batch Saving a single file

Explorer ,
Apr 18, 2019 Apr 18, 2019

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.

TOPICS
Scripting
3.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 25, 2019 Apr 25, 2019

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 origin

...
Translate
Adobe
Community Expert ,
Apr 19, 2019 Apr 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:

artboards.png

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2019 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2019 Apr 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2019 Apr 23, 2019

Same thing, always remembers the original folder and saves it back to that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2019 Apr 25, 2019

A script would be best, however it is more complex than my beginner scripting knowledge is capable of. It will be a good way to learn though. So, I just tested the batch action workflow and I have a two step result.

Here is the original action, it was recorded using destination folder for the export for screens steps that is different to the batch folder:

atn.png

Here is the action/batch, notice the override commands, selecting a new source folder for the new project input/output:

batch.png

And here is the output result:

batch-output.png

Unfortunately the save for screen PDF suffix is not honoured for PDF files (unlike JPG), so the _ProductionWorksheet text has to be added again against the PDF. This could be done manually or using many other methods, here I have used Adobe Bridge:

rename.png

So, not a great workflow, better than fully manual – but not as good as a single script run.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2019 Apr 25, 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)

OK here is a script that does half of what you require, the first 2 of 4 steps!

Save current master .ai file, create PDF of artboard one using filename and _ProductionWorksheet suffix. The suffix is hard coded however it could be changed to use the artboard name which should be the same anyway so I’m not going to sweat this too much for now.

I’ll try to add the JPEG save step for artboards 2 & 3 sometime later, however if somebody else wishes to chime in and supply code that would be great.

Refinement is of course possible, however it is probably best to get the script completed before that is attempted.

#target illustrator

// Run the menu command

// app.executeMenuCommand('save');

// Or use the DOM code instead

app.activeDocument.save();

// 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(/\.[^\.]+$, ""/)

// 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 + "_ProductionWorksheet.pdf"), opts);

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2019 Apr 25, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2019 Apr 25, 2019

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.");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2019 Apr 26, 2019

Wow, this is real good. Just tested it and works great - thank you so much for this.

I didn't even know where to start with Java, having no experience whatsoever.

I got "Hello World" working, but that wasn't much use to me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2019 Apr 26, 2019

My pleasure, I usually muck around with Photoshop scripts, this was my second attempt at Illustrator for a script of this complexity (which is rather simple). I definitely learned a lot, even though most of the code was harvested.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2019 Apr 26, 2019
LATEST

Good, I'm glad we both gained something - I felt bad for just asking for it outright, but after trying myself and failing I had no other option as I knew nothing.

You would not believe how much time you have saved me - I sometimes have to create upwards of 30 designs a day, creating/renaming/saving each file individually. You have essentially turned a days work into an hours work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2019 Apr 25, 2019

OK, the next incremental step, adding the two artboard saves as JPEG. I’m sure this bit could be cleaned up, but it works.

This script is a hack job and I’m sure that it could be coded cleaner from scratch, but for my scripting level I’m pretty happy so far with the Dr Frankenstein effort:

// 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, "")  

 

// 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 + "_ProductionWorksheet.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 + "_FrontView" 

var dest2 = originalDocPath + "/" + originalDocName + "_BackView" 

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.");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2019 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2019 Apr 23, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2019 Apr 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));

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2019 Apr 25, 2019

Cross posted here:

Automating File Export

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines