Setting the resolution output in an export PNG script

Explorer ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

I have created a simple script that loops through each artboard in an open illustrator document and exports it as a separate PNG file. All is working well except that I want to set the resolution to 150 dpi and not 72 dpi for production reasons. This is an option that you can set when exporting manually to PNG but I don't seem to be able to set it in the PNG options in the code, although the script runs without errors it ignores the resolution setting. Could someone let me know what I'm doing wrong, many thanks. Code as follows:

var doc = app.activeDocument;;//Gets the active document

var fileName = doc.name.slice(0, 9);//Gets the G Number

var numArtboards = doc.artboards.length;//returns the number of artboards in the document

var filePath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');

$.writeln("fleName= ",fleName)

$.writeln("numArtboards= ",numArtboards)

$.writeln("filePath= ",filePath);

var options = new ExportOptionsPNG24();

  

for (var i = 0; i < numArtboards; i++ ) {

    doc.artboards.setActiveArtboardIndex( i );

   

    option.resolution = 150;

    options.artBoardClipping = true; 

    options.matte = false;

    options.horizontalScale = 100;

    options.verticalScale = 100; 

    options.transparency = true; 

    var artboardName = doc.artboards.name;

    $.writeln("artboardName= ", artboardName);

        var destFile = new File(filePath + "/" + fileName + " " +  artboardName + ".png");

        $.writeln("destFile= ",destFile);

          doc.exportFile(destFile,ExportType.PNG24,options);

    }

TOPICS
Scripting

Views

2.2K

Likes

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

Adobe Community Professional , Jul 24, 2019 Jul 24, 2019
use document.imageCapture() function, it has a resolution property here's a sample https://community.adobe.com/t5/illustrator-discussions/export-symbols-as-png-script-with-resolution/m-p/8652400#M215910

Likes

Translate

Translate
Contributor ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

First thing i've noticed:

option.resolution = 150;

options.artBoardClipping = true;

There is a missing "s".

But yeah, there is no resolution property in ExportOptionsPNG24 at least there is no information about it in documentation.

I've found that the Document object has resolution property, maybe that's some way.

Document — Illustrator Scripting Guide 0.0.1 documentation

Likes

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
Explorer ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Thanks for that, I added the resolution line into the post at the end,  so missed the s off, its there in my original code. I'll take a look at the document object and sem if that helps. Thanks for you time

Likes

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 Professional ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

use document.imageCapture() function, it has a resolution property

 

here's a sample

https://community.adobe.com/t5/illustrator-discussions/export-symbols-as-png-script-with-resolution/...

Likes

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
LEGEND ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

"document.imageCapture()" greatly improved my workflow.

Likes

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
Explorer ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

LATEST

Thanks very much for that, it's made life a whole lot easier. Here is the code for the revised script, just in case anyone else needs to figure this out. It takes the boundaries of the artboard being . output as the clipping booundaries for the image

var doc = app.activeDocument;;//Gets the active document

var fileName = doc.name.slice(0, 9);//Gets the G Number

var numArtboards = doc.artboards.length;//returns the number of artboards in the document

var filePath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');

var options = new ImageCaptureOptions();

for (var i = 0; i < numArtboards; i++) {

  doc.artboards.setActiveArtboardIndex(i);

   var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];


  options.artBoardClipping = true;

  options.resolution = 150;

  options.antiAliasing = true;

  options.matte = false;

  options.horizontalScale = 108.3;

  options.verticalScale = 108.3;

  options.transparency = true;


   var artboardName = doc.artboards.name;

   var destFile = new File(filePath + "/" + fileName + " " + artboardName + ".png");

  doc.imageCapture(destFile, activeAB.artboardRect, options);

}

Likes

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