Skip to main content
brian_p_dts
Community Expert
Community Expert
July 15, 2022
Answered

[Scripting] Export each artboard as a JPG

  • July 15, 2022
  • 2 replies
  • 1222 views

Hello, I know you can select use multiple artboards for jpg export manually, but there doesn't seem to be a corresponding property in the DOM. I tried some of the solutions mentioned here, but I am still getting the full file for each export. 

Here is my routine. Am I missing something?

 

    var exportOptions = new ExportOptionsJPEG();
        exportOptions.artboardClipping = true;
        exportOptions.antiAliasing = false;
        exportOptions.quality = 100;    
    var doc = activeDocument;
    var outfol = Folder.desktop;
    var type = ExportType.JPEG;
    var dn = decodeURI(doc.name);
    var dnrx = /\.ai$/gi;
    var abs = doc.artboards;
    var n = abs.length;
    var i = 0;
    var fname;
    for (i; i < n; i++) {
        fname = dn.replace(dnrx,"-" + "0" + (i+1).toString().slice(-2) + ".jpg");
        abs.setActiveArtboardIndex(i);
        doc.exportFile(File(outfol + "/" + fname), type, saveOptions);
    }
    doc.close(SaveOptions.DONOTSAVECHANGES);

 

 

 

This topic has been closed for replies.
Correct answer sttk3

In Illustrator 2018 or later, it is easier to use exportForScreens.

Script for ExportForScreensOptionsJPEG() not working.

 

If you are on macOS, you can find the documentation here.

/Library/Application Support/Adobe/Scripting Dictionaries CC/Illustrator 2022/omv.xml

 

2 replies

sttk3Correct answer
Legend
July 15, 2022

In Illustrator 2018 or later, it is easier to use exportForScreens.

Script for ExportForScreensOptionsJPEG() not working.

 

If you are on macOS, you can find the documentation here.

/Library/Application Support/Adobe/Scripting Dictionaries CC/Illustrator 2022/omv.xml

 

brian_p_dts
Community Expert
Community Expert
July 15, 2022

I looked at the documentation, but don't see how to set the resolution to 300. 

Legend
July 15, 2022

The parameters are written in omv.xml, so you can guess how to use them from their names. A sample is here.

var optionsJPEG = new ExportForScreensOptionsJPEG() ;
optionsJPEG.scaleType = ExportForScreensScaleType.SCALEBYRESOLUTION ;
optionsJPEG.scaleTypeValue = 300 ;
m1b
Community Expert
Community Expert
July 15, 2022

Hi @brian_p_dts, it doesn't seem to be documented properly, but if you look at, say, ExportOptionsSVG, you will see two properties that you can set in your ExportOptionsJPEG: artboardRange and saveMultipleArtboards.

- Mark

brian_p_dts
Community Expert
Community Expert
July 15, 2022

Thanks, Mark. I tried saveMultipleArtboards = true, with nothing. I then iterated through the artboards and set exportOptions.artboardRange = abs[i].name and exporting each file that way, and still got 5 versions of the full doc. Is there some default preference maybe that I need to set? 

 

brian_p_dts
Community Expert
Community Expert
July 15, 2022

Updated code: 

 

var exportOptions = new ExportOptionsJPEG();
        //exportOptions.artboardClipping = true;
        exportOptions.saveMultipleArtboards = true;
        exportOptions.antiAliasing = false;
        exportOptions.quality = 100;    
    var doc = activeDocument;
    var outfol = Folder.desktop;
    var type = ExportType.JPEG;
    var dn = decodeURI(doc.name);
    var dnrx = /\.ai$/gi;
    var abs = doc.artboards;
    var n = abs.length;
    var i = 0;
    var fname;
    for (i; i < n; i++) {
        fname = dn.replace(dnrx,"-" + "0" + (i+1).toString().slice(-2) + ".jpg");
        exportOptions.artboardRange = abs[i].name;
        abs.setActiveArtboardIndex(i);
        doc.exportFile(File(outfol + "/" + fname), type, exportOptions);
    }
    doc.close(SaveOptions.DONOTSAVECHANGES);

 


Eureka! I (kind of) figured it out. I had artBoardRange as artboardRange. Why wouldn't it throw an error!?!?! Now, how can I ensure that this exports at 300dpi? I tried setting exportOptions.resolution = 300, but still coming out at 72.