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

[Scripting] Export each artboard as a JPG

Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

 

 

 

TOPICS
Scripting

Views

448

Translate

Translate

Report

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 , Jul 14, 2022 Jul 14, 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

 

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Hi @brianp311, 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

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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? 

 

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

LATEST

Yep. I got your code working, too. You can use the index (i) for the artboardRange. Also I've got some code where "exportOptions.quality" is "exportOptions.qualitySetting", not sure which is right.

One more thing: I would not be surprised if exporting as jpg does not set the files "resolution"—I think all it cares about is the pixel dimensions, so use horizontal and vertical scale.

And, as @sttk3 mentioned, the newer exportForScreens is definitely worth looking at.

- Mark

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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 ;

Votes

Translate

Translate

Report

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 ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Thanks, I think this should work. Much appreciated. 

Votes

Translate

Translate

Report

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