Skip to main content
New Participant
August 9, 2022
Answered

Convert 10000 ai files into png format and save in same existing folder

  • August 9, 2022
  • 3 replies
  • 683 views

Hello Community, I have 10,000+ individual ai files stored in folders. For the most part, there are 2-3 files in each folder. I need to save a png copy of each individual file, and keep them in the same folder as their respective ai file. I also would like to save the naming conventions of each file. Obviously, doing this manually would take a lifetime. I'm looking for a solution to achieve this overnight if possible. Any information or feedback on how I can manage this would be much appreciated. Thanks in advance!  

This topic has been closed for replies.
Correct answer Charu Rajput

For specifing the resolution you need to use the imageCapture method. Below is the another version of the script, change value of the resolution as required.

function main() {
    var folder = Folder.selectDialog('Select folder.', '~');
    if (folder) {
        if (folder) {
            var _files = folder.getFiles('*.ai');
            for (var i = 0; i < _files.length; i++) {
                doc = app.open(File(_files[i]));
                doc.activate();
                var resolution = 200;
                var opts = new ImageCaptureOptions();
                opts.resolution = resolution;
                opts.antiAliasing = true;
                opts.transparency = true;
                try {
                    var pngFile = new File(folder + '/' + doc.name.split('.')[0] + '.png');
                    doc.imageCapture(pngFile, doc.geometricBounds, opts);
                }
                catch (e) {
                    alert('Export of file "' + doc.name + '" failed.\n' + e.message);
                    return;
                } finally {
                    doc.close(SaveOptions.DONOTSAVECHANGES);
                }
            }
            alert('Success!\nPNGs saved to ' + folder);
        }
    }
}

main();

 

3 replies

New Participant
September 12, 2022

Hgffjf

Charu Rajput
Community Expert
Community Expert
August 9, 2022

Hi,

You can try following script

function main() {
    var folder = Folder.selectDialog('Select folder.', '~');
    if (folder) {
        if (folder) {
            var _files = folder.getFiles('*.ai');
            for (var i = 0; i < _files.length; i++) {
                doc = app.open(File(_files[i]));
                doc.activate();
                try {
                    doc.exportFile(new File(folder + '/' + doc.name.split('.')[0] + '.png'), ExportType.PNG24, new ExportOptionsPNG24());
                }
                catch (e) {
                    alert('Export of file "' + doc.name + '" failed.\n' + e.message);
                    return;
                } finally {
                    doc.close(SaveOptions.DONOTSAVECHANGES);
                }
            }
            alert('Success!\nPNGs saved to ' + folder);
        }
    }
}

main();

 

You can choose folder where ai files exists and script will save the document as png in the same folder. 

 

NOTE: As you said there are many folders, currently you need to run this script for all folders each time. But if there is any structure of your folder like folders and subfolders then script can be modified so that it will run for all files for all folders all together.

 

Best regards
New Participant
August 10, 2022

This is awesome! This is exactly what I was looking for. One quick follow-up question.. How can I adjust the settings so that it saves the png at the highest resolution?  

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
August 10, 2022

For specifing the resolution you need to use the imageCapture method. Below is the another version of the script, change value of the resolution as required.

function main() {
    var folder = Folder.selectDialog('Select folder.', '~');
    if (folder) {
        if (folder) {
            var _files = folder.getFiles('*.ai');
            for (var i = 0; i < _files.length; i++) {
                doc = app.open(File(_files[i]));
                doc.activate();
                var resolution = 200;
                var opts = new ImageCaptureOptions();
                opts.resolution = resolution;
                opts.antiAliasing = true;
                opts.transparency = true;
                try {
                    var pngFile = new File(folder + '/' + doc.name.split('.')[0] + '.png');
                    doc.imageCapture(pngFile, doc.geometricBounds, opts);
                }
                catch (e) {
                    alert('Export of file "' + doc.name + '" failed.\n' + e.message);
                    return;
                } finally {
                    doc.close(SaveOptions.DONOTSAVECHANGES);
                }
            }
            alert('Success!\nPNGs saved to ' + folder);
        }
    }
}

main();

 

Best regards
Scott Falkner
Community Expert
Community Expert
August 9, 2022

I would probably try a batch action in Photoshop. Open Photoshop, open the Actions panel, then create a new action. This will start recoring. Open a file and specify the resolution for rendering, then save as PNG. Now use Photoshop’s Batch actions (File > Automate > Batch) to convert the files. I think you will need to do one folder at a time.