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

[Scripting] Export each artboard as a JPG

Community Expert ,
Jul 14, 2022 Jul 14, 2022

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
1.1K
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

Enthusiast , 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

 

Translate
Adobe
Community Expert ,
Jul 14, 2022 Jul 14, 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

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

 

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

 

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

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. 

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

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
Enthusiast ,
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

 

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

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

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

Thanks, I think this should work. Much appreciated. 

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