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

Help!I have a script to export layers to jpg one by one, but I need to access the "use artboard" option

New Here ,
Jan 23, 2015 Jan 23, 2015

Copy link to clipboard

Copied

I want the exported pictures to use the artboard's size. Thanks in advance.

var folder = Folder.selectDialog();

var document = app.activeDocument;

if(document && folder)

{   

    var options = new ExportOptionsJPEG();

    options.antiAliasing = true; 

    options.qualitySetting = 100;   

    options.optimization = true;

    options.croppingMaskClipping = true;   

     

    //scale to 500dpi

    options.verticalScale = 500;

    options.horizontalScale = 500;

    

    var n = document.layers.length;

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

        hideAllLayers();

        var layer = document.layers;

        layer.visible = true;

        var file = new File(folder.fsName+"/"+layer.name+".jpg");

        document.exportFile(file,ExportType.JPEG,options);

    }

    //to show all layers visible when done:

    showAllLayers();

}

function hideAllLayers()

{

    forEach(document.layers, function(layer) { 

        /** 

        if there is one or more layers called 'ABC' in the .ai file, it will always be part of the export.

        */

        if( layer.name != "ABC"){

            layer.visible = false;

        }

    });

}

function showAllLayers()

{

    forEach(document.layers, function(layer) {

            layer.visible = true; 

    });       

}

function forEach(collection, fn)

{

    var n = collection.length;

    for(var i=0; i<n; ++i)

    {

        fn(collection);

    }

}

TOPICS
Scripting

Views

445

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

Engaged , Jan 23, 2015 Jan 23, 2015

Hi there...

This isn't tested, but I believe that you should just need to add one line --
......

    var options = new ExportOptionsJPEG();
    options.antiAliasing = true; 
    options.qualitySetting = 100;   
    options.optimization = true;
    options.croppingMaskClipping = true;
    options.artBoardClipping = true;

     
    //scale to 500dpi
    options.verticalScale = 500;
    options.horizontalScale = 500;

......

Hope this helps!

-TT

Votes

Translate

Translate
Adobe
Engaged ,
Jan 23, 2015 Jan 23, 2015

Copy link to clipboard

Copied

Hi there...

This isn't tested, but I believe that you should just need to add one line --
......

    var options = new ExportOptionsJPEG();
    options.antiAliasing = true; 
    options.qualitySetting = 100;   
    options.optimization = true;
    options.croppingMaskClipping = true;
    options.artBoardClipping = true;

     
    //scale to 500dpi
    options.verticalScale = 500;
    options.horizontalScale = 500;

......

Hope this helps!

-TT

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
New Here ,
Jan 23, 2015 Jan 23, 2015

Copy link to clipboard

Copied

That helps, Thank a lot!

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
Engaged ,
Jan 23, 2015 Jan 23, 2015

Copy link to clipboard

Copied

LATEST

You're welcome. Nice avatar!

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