Skip to main content
Aprking
Inspiring
August 31, 2023
Answered

How to exclude artboard name when exporting JPEGs with "exportForScreens" script in Illustrator?

  • August 31, 2023
  • 1 reply
  • 1075 views

Hello everyone!

I have a question about using a script in Illustrator to export JPEGs. When using the following code: 

doc.exportForScreens(jpegOutPath, ExportForScreensType.SE_JPEG100, jpegOptions, whatToExport, 'art_');

the exported JPEG file names contain the name of the artboard. How can I export the JPEGs without the artboard name in the file name?

Thank you!

 

This topic has been closed for replies.
Correct answer jduncan

What do you want to name them then? I see the prefix "art_" but if you export multiple artboards they would successfully overwrite each other if they didn't include the artboard name. I have a method of doing what you are asking but you'll need to differentiate the filenames in some way so they don't overwrite each other. If you are only exporting one artboard at a time (I don't know what you set in your `whatToExport` var) then that is pretty easy as shown in the code below.

var doc = app.activeDocument;

var artboard_idx = 0; // artboard you want to export (0-based index)
var artboard = doc.artboards[artboard_idx];
var prefix = "art_";

var jpegParam = new ExportForScreensOptionsJPEG();
var whatToExport = new ExportForScreensItemToExport();
whatToExport.artboards = artboard_idx + 1 + "";

doc.exportForScreens(
  doc.path,
  ExportForScreensType.SE_JPEG100,
  jpegParam,
  whatToExport,
  prefix
);

// When exporting artboard using the exportForScreens method, the api adds
// "Artboad" to the actual artboard name resulting in `{prefix}Artboard X.{extension}`
// To be able to correctly name the exported file, I am recreating the known
// naming convention with a new `file` object to that path and then just renaming the file.
exportedFile = new File(doc.path + "/" + prefix + artboard.name + ".jpg");
exportedFile.rename(prefix + ".jpg");

1 reply

jduncan
Community Expert
jduncanCommunity ExpertCorrect answer
Community Expert
August 31, 2023

What do you want to name them then? I see the prefix "art_" but if you export multiple artboards they would successfully overwrite each other if they didn't include the artboard name. I have a method of doing what you are asking but you'll need to differentiate the filenames in some way so they don't overwrite each other. If you are only exporting one artboard at a time (I don't know what you set in your `whatToExport` var) then that is pretty easy as shown in the code below.

var doc = app.activeDocument;

var artboard_idx = 0; // artboard you want to export (0-based index)
var artboard = doc.artboards[artboard_idx];
var prefix = "art_";

var jpegParam = new ExportForScreensOptionsJPEG();
var whatToExport = new ExportForScreensItemToExport();
whatToExport.artboards = artboard_idx + 1 + "";

doc.exportForScreens(
  doc.path,
  ExportForScreensType.SE_JPEG100,
  jpegParam,
  whatToExport,
  prefix
);

// When exporting artboard using the exportForScreens method, the api adds
// "Artboad" to the actual artboard name resulting in `{prefix}Artboard X.{extension}`
// To be able to correctly name the exported file, I am recreating the known
// naming convention with a new `file` object to that path and then just renaming the file.
exportedFile = new File(doc.path + "/" + prefix + artboard.name + ".jpg");
exportedFile.rename(prefix + ".jpg");
Aprking
AprkingAuthor
Inspiring
August 31, 2023

Thank you very much for your response! I originally planned to use ‘art_’ for variable naming, but now I’m prepared to use the artboard name for variable naming. Of course, your method may be more convenient. Also, does ‘ExportForScreensType.SE_JPEG100’ have only four values: 20_50_80_100? Thanks again for your response!

Sergey Osokin
Inspiring
September 2, 2023

Yes. Adobe's documentation only lists four values: SE_JPEG100, SE_JPEG80, SE_JPEG50, SE_JPEG20.