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

How to use JavaScript to export to PNG/TIFF as multiple assets?

Community Beginner ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

I have a lot of .ai files with logo and I need to export them into PNG files. Is there an antomatic way of doing it? I know you cannot record the export part in Action...

TOPICS
Scripting

Views

1.1K

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 2 Correct answers

Community Expert , Dec 11, 2021 Dec 11, 2021

Hi,

Yes this possible via script. I have simple script that exports all selected items of the active document as PNG, but this can be modified to run on all multiple documents.

My question, is do you want to export all items inside all documents or some specific? Coudl you share some ai sample files

 

Below is sample script

var doc = app.activeDocument;
var docAssets = doc.assets;
var assetIDArray = new Array();
var itemToExport = new ExportForScreensItemToExport();
itemToExport.artboards = '';
...

Votes

Translate

Translate
Community Expert , Dec 23, 2021 Dec 23, 2021

Hi,

You can use following snippet for your documents. When you run the script it will ask for the folder where source file exists. So select source_files folder in your case and png will be exported at the Desktop.

 

var _folder = Folder.selectDialog();
if (_folder != null) {
    var _files = _folder.getFiles('*.ai');
    for (var f = 0; f < _files.length; f++) {
        var doc = app.open(_files[f]);
        var docAssets = doc.assets;
        var assetIDArray = new Array();
        var itemToE
...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Hi,

Please see the thread below, if that helps you

https://community.adobe.com/t5/illustrator-discussions/collect-for-export-as-multiple-assets/td-p/12...

 

Best regards

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 Beginner ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

that is what I'm doing for the moment. The painful things is to open up hundreds of .ai files one by one, export them as multiple assets, and close them one by one. 

I think there is a way to speed it up by using scrips since I only need to open a file and export them to png, right?

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 ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Hi,

Yes this possible via script. I have simple script that exports all selected items of the active document as PNG, but this can be modified to run on all multiple documents.

My question, is do you want to export all items inside all documents or some specific? Coudl you share some ai sample files

 

Below is sample script

var doc = app.activeDocument;
var docAssets = doc.assets;
var assetIDArray = new Array();
var itemToExport = new ExportForScreensItemToExport();
itemToExport.artboards = '';
itemToExport.document = false;
var assetArray = new Array();
for (var i = 0; i < app.selection.length; i++) {
    var asset = docAssets.add(app.selection[i]);
    assetIDArray.push(asset.assetID);
}
itemToExport.assets = assetIDArray;
var options = new ExportForScreensOptionsPNG24();
app.activeDocument.exportForScreens(File('~/Desktop'), ExportForScreensType.SE_PNG24, options, itemToExport);

 

NOTE: This will export only selected items of the active document. if you answer above quetsion, we can help you in right direction.

Best regards

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 Beginner ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Thank you soooo much!! it works on my mac!

To answer your question: I need to export all items inside all documents. it would be better if I can only give a path to all of the .ai and an automation could take process and output .pngs. if such automation works then these .pngs need to be put into different folders named by their source .ai files. It would be very hard to look up if all .pngs are saved in the same folder  because their name is meaningless("Asset" + numbers).

I also upload a sample file here.

many thanks!

 

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 Beginner ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

I just find out I cannot upload .ai as a attachment. I tried to change its suffix to other qualified format and none of them worked. 

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 ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

upload to google drive, dropbox, creative cloud or similar and post the link here

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 Beginner ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

LATEST

Hi,

You can use following snippet for your documents. When you run the script it will ask for the folder where source file exists. So select source_files folder in your case and png will be exported at the Desktop.

 

var _folder = Folder.selectDialog();
if (_folder != null) {
    var _files = _folder.getFiles('*.ai');
    for (var f = 0; f < _files.length; f++) {
        var doc = app.open(_files[f]);
        var docAssets = doc.assets;
        var assetIDArray = new Array();
        var itemToExport = new ExportForScreensItemToExport();
        itemToExport.artboards = '';
        itemToExport.document = false;
        var assetArray = new Array();
        var _layer = doc.layers[0];
        for (var i = 0; i < _layer.groupItems.length; i++) {
            var asset = docAssets.add(doc.groupItems[i]);
            assetIDArray.push(asset.assetID);
        }
        itemToExport.assets = assetIDArray;
        var options = new ExportForScreensOptionsPNG24();
        app.activeDocument.exportForScreens(File('~/Desktop'), ExportForScreensType.SE_PNG24, options, itemToExport);
    }
}

 

Best regards

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