14 Replies Latest reply on May 23, 2012 1:34 PM by timlogochair

    Modify a script help?

    timlogochair Level 1

      I have a script that needs to be tweaked very slightly.  Right now this script is setup to save out files and rename them as follows:

      current document file name + "-" + artboard name + (rename files from .ai to .pdf)

       

      I need this script tweaked so that the exported file names are as follows:

      artboard name + "-" + current document file name + (rename from .ai to .pdf)

       

      Here's the script that needs to be tweaked:

       

       

      #target illustrator

       

      function artboardsToPDFs() {

       

           if (app.documents.length = 0) {

       

                return;

       

           } else {

       

                var docRef = app.activeDocument;

               

                var docName = docRef.name;

       

                var baseName = docName.replace(/.ai$/,'');

       

           var dF = Folder(Folder.desktop + "/AI PDF's");

               

                if (!dF.exists) dF.create();

             

                var aB = docRef.artboards;

               

                var autoNames = Array();

               

                for (var i = 0; i < aB.length; i++) {

               

                     var abName = aB[i].name;

               

                     autoNames.push(baseName + '_' + abName + '.ai');

               

                }

               

                if (!docRef.saved) docRef.save();

               

                var aiOpts = new IllustratorSaveOptions();

               

                aiOpts.compatibility = Compatibility.ILLUSTRATOR13;

                aiOpts.pdfCompatible = true;

                aiOpts.saveMultipleArtboards = true;

               

                var saveFile = File(dF.fsName + '/' + docName);

               

                docRef.saveAs(saveFile, aiOpts);

               

                docRef.close(SaveOptions.DONOTSAVECHANGES);

               

                saveFile.remove();

               

                renameFiles(dF, autoNames);

           }

      }

       

      artboardsToPDFs();

       

       

      function renameFiles(dir, fL) {

       

           for (var i = 0; i < fL.length; i++) {

                    

                var f = File(dir.fsName + '/' + fL[i]);

               

                if (f.exists) {

                              

                     var reName = f.name.replace('_','-');

          

                     f.rename(reName);

                    

                     f = File(dir.fsName + '/' + reName);

                    

                     reName = f.name.replace(/\.ai$/,'.pdf');

                    

                     t = File(dir.fsName + '/' + reName);

                    

                     if (t.exists) t.remove();

          

                     f.rename(reName);

                    

                }

           }

      }