4 Replies Latest reply on Feb 12, 2016 6:31 AM by scottRaysNI

    Batch processing hundreds of Illustrator files?

    scottRaysNI Level 1

      Good morning,

       

      Our software has thousands of icons all created in Illustrator, and we need to batch export all icons from hundreds of .ai files. I am curious what solutions others have people have come up with?

       

      Here is a list of what we are looking to do:

      • Ability to be called from the command-line
      • Ability to pass in what files to process
      • Ability to run in house scripts on loaded file
      • Ability to pass in the target folder to place the generated files
      • Ability to close Illustrator when we are finished

       

      I would love to hear if any other developers have been faced with this issue, and how they solved it. I imagine other developers have been faced with this issue?

       

       

      Cheers,

      Scott

        • 1. Re: Batch processing hundreds of Illustrator files?
          Silly-V Adobe Community Professional

          So, you're going to have 1 file with many components which you're looking to batch-export, and you're looking to do this process in a batch as well?

          • 2. Re: Batch processing hundreds of Illustrator files?
            scottRaysNI Level 1

            Thanks for reply Silly-V.

             

            Currently our files have anywhere from 5 - 100 icons on separate artboards.

             

            We run a custom script that exports each artboard as separate .xml file(custom script generates a file with raw xml path data, custom properties, etc).

             

            We want to open every .ai file in a directory path one at a time, run our internal export script generating .xml files, and save them to a specific location.

             

            I was curious if anyone has needed to automated batching a lot of Illustrator files, and what would be the best approach? I am not necessarily looking for a solution, more interesting in hearing what is the preferred approach? VBScript? BridgeTalk? C#?

             

            Thanks for sharing any thoughts!

            Scott

            • 3. Re: Batch processing hundreds of Illustrator files?
              Silly-V Adobe Community Professional

              It looks like what you want to do can be simply accomplished by using Illustrator's Actions and batch feature. You can make sure your script is inside the File > Scripts menu item and then you can record an action which uses this menu item (use "insert menu item" in the flyout menu to find this script in File > Scripts). Then you can batch-process all the files in a directory, and your XML file's destinations will need to be set by whatever the script has for its destination.

              • 4. Re: Batch processing hundreds of Illustrator files?
                scottRaysNI Level 1

                So after a lot of testing, my solution was write a recursive function that finds all .ai files i a given path and stores the paths in an array:

                 

                // path hardcoded for testing is replaced with dialog option in final

                var rootFolder = Folder("E:\\temp\\Production%20Finals");

                var numAIFiles = 0;

                var allAIFiles = [];

                 

                function filesInFolder(startFolder) {

                    var folderContents;

                 

                    folderContents = startFolder.getFiles();

                 

                    for (var y = 0; y < folderContents.length; y++) {

                 

                        // checks if object in file array is a Folder object, then recursively runs fucntion again

                        //  the recursive is then assigned the file array Folder path

                        if (folderContents[y].toLocaleString() == "[object Folder]") {

                       

                          //  set recursive function call to newly found [object Folder] path

                          filesInFolder(Folder(folderContents[y].path + "//" + folderContents[y].name));

                        }     

                        // searches file name for .ai in file name

                        // when found, add .ai file path to an array

                        //  array of file paths are sent to createArtboardFile()

                        if (folderContents[y].name.match(/(\.ai)+/)) {

                     

                          // adds path to .ai file to an array

                          allAIFiles.push(folderContents[y].fullName);

                          numAIFiles++;

                        }

                    }

                }


                For testing purposes I send that array of file paths to a function that opens all files, find artboard names, and saves them to a .txt file in the path folder:


                function createArtboardFile(fileArray) {

                    var filesProcessed =0;

                    var artboardTotal = 0;

                   

                    // extracts folder location

                    var reg = /[^\\]+$/g;

                    var folderLocation = rootFolder.fsName.match(reg);

                   

                    // file headers and footers

                    var arrowEnd = "<END>\n\n";

                    var header = "\n\n< --- FILE PATH --- >\n";

                    var artboardHeader = "< --- ARTBOARDS --- >\n";

                   

                    // create a text file to store all the file and artboard data

                    var file_ArtboardNames = File(rootFolder + '/' + 'artboardsIn_'+ folderLocation + '.txt');

                    file_ArtboardNames.open("w");

                 

                    for (var t = 0; t < fileArray.length; t++) {

                     

                        // create a File object, then open file in Illustrator

                        var file_openingTemp = File(fileArray[t]);

                        app.open(file_openingTemp);

                       

                        //  write file header break

                        file_ArtboardNames.write(header + file_openingTemp.fsName + "\n" + arrowEnd + artboardHeader);

                        var artboardName = app.documents[0].artboards;

                 

                 

                        for (var j = 0; j < app.activeDocument.artboards.length; j++) {

                           

                            // write artboard names into file

                            file_ArtboardNames.write(artboardName[j].name + "\n");

                            artboardTotal++;

                        }

                        app.activeDocument.close();

                        file_ArtboardNames.write(arrowEnd);

                        filesProcessed++;

                    }

                  file_ArtboardNames.write("\n\nTotal number of files found = " + numAIFiles +"\n");

                  file_ArtboardNames.write("Total number of files processed = " + filesProcessed +"\n");

                  file_ArtboardNames.write("Total number of artboards found = " + artboardTotal);

                  file_ArtboardNames.close();

                }