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

Error When Exporting Artboards as JPG Using Script

New Here ,
Oct 20, 2024 Oct 20, 2024

Copy link to clipboard

Copied

        if (exportArtboards) {
            var baseFileName = doc.name.replace(/\.[^\.]+$/, '');
            var fileFolder = doc.path;

            for (var n = 0; n < doc.artboards.length; n++) {
                doc.artboards.setActiveArtboardIndex(n);
                var artboardBounds = doc.artboards[n].artboardRect;

                var artboardWidth = artboardBounds[2] - artboardBounds[0];
                var artboardHeight = artboardBounds[1] - artboardBounds[3];

                var targetWidth = 1280;
                var targetHeight = Math.round((artboardHeight / artboardWidth) * targetWidth);

                var fileName = (doc.artboards.length === 1 ? baseFileName : baseFileName + (n + 1)) + ".jpg";
                var exportFile = new File(fileFolder + "/" + fileName);
                var exportOptions = new ExportOptionsJPEG();
                exportOptions.qualitySetting = 60;
                exportOptions.artBoardClipping = true;

                exportOptions.horizontalScale = (targetWidth / artboardWidth) * 100;
                exportOptions.verticalScale = (targetHeight / artboardHeight) * 100;

                $.writeln("Artboard bounds: " + artboardBounds);
                $.writeln("Original width: " + artboardWidth + ", height: " + artboardHeight);
                $.writeln("Export target width: " + targetWidth + ", height: " + targetHeight);
                $.writeln("Horizontal scale: " + exportOptions.horizontalScale + ", Vertical scale: " + exportOptions.verticalScale);

                doc.exportFile(exportFile, ExportType.JPEG, exportOptions);
            }
        }

I used the script above to export artboards as JPG images. The problem now is that if the artboard size is too small, an error message appears: 'Specified value greater than maximum allowed value.' After checking the documentation, I found that this error occurs if the scale factor is greater than 7.76. Is there any way to solve this?

TOPICS
Scripting

Views

97

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
Adobe
Community Expert ,
Oct 20, 2024 Oct 20, 2024

Copy link to clipboard

Copied

exportFile is limited to that scale factor; exportForScreens allows you to specify a larger number.


A good sample is written by @m1b on this page. Please refer to it.

Javascript for using Asset Export

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 ,
Oct 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

LATEST

Hi @Liu254468142lhe if you need to be able to (a) specify an arbitrary width and height, and (b) handle an arbitrary sized artboard, then there will always be cases where the "scaleFactor" is too high for the jpeg export API. The next approach—if you are willing to put more work into your script—is to scale the actual artwork, including artboard(s) and then export at 100%.

- 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