20 Replies Latest reply on Jun 7, 2017 7:28 AM by miss-charlotte

    Illustrator batch export to same folder

    miss-charlotte Level 1

      Have a folder containing several subfolders, each folder has a few EPS files. Ran a batch with an export script I created.

       

      Works great except all files are being exported into one folder.

       

      How do I get each to be saved into their respective folders, without interruption?

        • 1. Re: Illustrator batch export to same folder
          Loic.Aigon Adobe Community Professional

          File instances have a parent property that points to the folder where the file is located

           

          var file = doc.fullName;

          doc.save ( File ( file.parent+"/"+file.name.replace ( /\.ait?/i, "")+".pdf", … )

          • 2. Re: Illustrator batch export to same folder
            miss-charlotte Level 1

            Thank you Loic. Apologies, I misspoke -- it was an Action I had set up in Illustrator, not a Script. Is there anything I change in the Action or Batch preferences OR do I need to use/create a Script?

            • 3. Re: Illustrator batch export to same folder
              Loic.Aigon Adobe Community Professional

              Hi,

              I think a script is better and not specifically hard to set:

               

              var Lib = {
                getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )
                {
                var exts = aExtensions? aExtensions.join("|") : ".+" ;
                var pattern = new RegExp ( "\\."+exts+"$", "g" );
                var files = aFiles? aFiles : [];
                var filterFunction = function(file)
                {
                return pattern.test ( file.name );
                }
              
                if ( bRecursive )
                {
                var foFiles = fo.getFiles();
                while (  f = foFiles.shift() )
                {
                if ( f instanceof Folder )
                {
                if (includeFolder===true) files[ files.length ] = f;
              
                this.getFiles ( f, aExtensions, true, files );
                }
                if ( f  instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" ) 
                files[ files.length ]  = f;
                }
              
                return files;
                }
              
                else
                {
                return fo.getFiles ( filterFunction );
                }
                },
              
              
                exportFile:function(file, opts) {
              
                var doc = app.open ( file ), data = {ok:true};
                try {
                doc.saveAs ( File ( file.parent+"/"+file.name.replace ( /\.eps?$/i, "" )+".pdf" ), opts);
                }
                catch(err) {
                data.ok = false;
                data.message = "⚠ "+file.name+" couldn't exported cause :"+err.message ;
                }
                doc.close ( SaveOptions.DONOTSAVECHANGES );
              
                return data;
                },
              
              
                log:function(msg) {
                var f = File ( Folder.desktop+"/batchExport.txt" );
                f.open('a');
                f.writeln ( msg );
                f.close();
                },
              
              
                getPDFOpts:function() {
                var opts = new PDFSaveOptions();
                opts.preserveEditability = true;
                //whatever options you may want to set here
              
                return opts;
                }
              }
              
              
              var main = function() {
                var fo = Folder.selectDialog("Please choose a folder"),
                files,n = 0,
                uip, result, pdfOpts, errors = [];
              
                if ( !fo ) return;
              
                files = Lib.getFiles ( fo, ["eps"], true );
              
                n = files.length;
              
                if ( !n ) {
                alert("No files could be found");
                return;
                }
              
                pdfOpts = Lib.getPDFOpts();
              
                uip = app.userInteractionLevel;
                app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
              
                while (n--) {
                result = Lib.exportFile ( files[n], pdfOpts );
                !result.ok && errors.push ( result.message );
                }
              
              
                app.userInteractionLevel = uip;
                errors.length && Lib.log ( errors.join("\r") );
                alert( errors.length? "Some errors occured. Check log on Desktop" : "Everything worked smoothly" );
              
              }
              
              
              main();
              

               

              HTH

               

              Loic

              Ozalto | Productivity Oriented - Loïc Aigon

              • 4. Re: Illustrator batch export to same folder
                Silly-V Adobe Community Professional

                If you want to keep your batch action export in the exact folders where they are picked from, why not just select "Save and Close" as the option for 'destination'?

                • 5. Re: Illustrator batch export to same folder
                  miss-charlotte Level 1

                  Thank you Silly, and Loic for the great script. Silly, yes I did try that initially...

                   

                  It seems the issue lies in my Action. The Action recorded/remembers the designation folder when I created it. After reading other's posts about this issue I see there isn't an easy way around this in Illustrator. I'm new at this so pardon my ignorance.

                  • 6. Re: Illustrator batch export to same folder
                    miss-charlotte Level 1

                    Your script for PDF export works great Loic. I will try to update it for PNG export. Thanks!

                    • 7. Re: Illustrator batch export to same folder
                      Silly-V Adobe Community Professional

                      Try an experiment if you can: when you export a copy (or save) the file with an action, make sure not to change the default file name provided.

                      • 8. Re: Illustrator batch export to same folder
                        williamadowling Level 4

                        IIRC an action saves an absolute path to the location that you originally saved to when you created the action. I don't believe it's able to make a reference to a relative folder path.

                        • 9. Re: Illustrator batch export to same folder
                          miss-charlotte Level 1

                          Yes William, that's what I'm finding with Illustrator.

                           

                          Photoshop, on the other hand, works great. Created my export PNG Action then ran Batch w Include All Subfolders / Suppress File Open Dialogs / Destination: Save and Close / Override Save As.

                           

                          So I'll use Photoshop or find a script to run in Illustrator (not having much luck tweaking above script)

                          • 10. Re: Illustrator batch export to same folder
                            Silly-V Adobe Community Professional

                            I wanna do a test for my own knowledge on this when I get a chance.

                            • 11. Re: Illustrator batch export to same folder
                              williamadowling Level 4

                              By all means have a go. Perhaps you'll see something i didn't. But it seems pretty clear to me. I just did a quick test and the result was what i expected. Also when you look at the action in the actions panel, under the Save As 'command', it shows the absolute path to wherever the file was saved to when the action was created.

                               

                              My original thought was "well duh, that's because you used save as". But of course, that's the only way you could do it. You can't do a simple "save" because then what would be the point of creating an action that just saves a file without changing it's filetype etc.

                               

                              I got the same result when creating an action that exports something into it's existing folder.

                              • 12. Re: Illustrator batch export to same folder
                                Silly-V Adobe Community Professional

                                I thought that "Save and Close" would do this, if we are starting with EPS files in a folder tree and the result is to just process those files, each one should be overwritten.

                                • 13. Re: Illustrator batch export to same folder
                                  williamadowling Level 4

                                  Oh, i certainly could have mis-read the original post. I thought that a "save as eps" was part of the thing. i guess i don't know what the action is doing.

                                   

                                  Certainly if there's no save command in the action, save and close will save the file right back into it's location just as you said.

                                   

                                  Words are hard. Misunderstandings abound. Shame permeates.

                                  • 14. Re: Illustrator batch export to same folder
                                    Silly-V Adobe Community Professional

                                    Oh, no, I think it was I who had misunderstood the situation. The objective is to export different files out of the EPS files, which are not EPS then.

                                     

                                    Yea a script would be useful, but I am trying to think of how to make a nice generic script which can be played within the action..., and I am thinking that a script would be better than the batch process since you can play a script with an action, but I heard that it crashes when you try to play an action from a script that's already being played by an action. Lol

                                    I'm now thinking for a less hard-coded way to give the user the export process, such as providing a saved action file instruction - the script could use those actions and replace the destination folder string inside, but keep all the user preferences.

                                    • 15. Re: Illustrator batch export to same folder
                                      miss-charlotte Level 1

                                      No shame. I'm exporting existing EPS files as transparent PNGs (1 main folder with many sub folders). Alas, the recorded Action remembers the original designation as recorded.

                                      • 16. Re: Illustrator batch export to same folder
                                        williamadowling Level 4

                                        Yea.. a script is going to have to be the way to go then.

                                        • 17. Re: Illustrator batch export to same folder
                                          Loic.Aigon Adobe Community Professional

                                          miss-charlotte settings svg as export format isn't  a big deal. Will provide a fix when i come back at the offic.

                                          • 18. Re: Illustrator batch export to same folder
                                            miss-charlotte Level 1

                                            Loic, that would be great! Your PDF script above worked well. If it could be tweaked to export transparent, 300 ppi, PNG that would be great. I don't need them to open up/launch at the end.

                                            • 19. Re: Illustrator batch export to same folder
                                              Loic.Aigon Adobe Community Professional

                                              here is the PNG

                                              var Lib = {  
                                                getFiles : function ( fo, aExtensions, bRecursive, aFiles, includeFolder )  
                                                {  
                                                var exts = aExtensions? aExtensions.join("|") : ".+" ;  
                                                var pattern = new RegExp ( "\\."+exts+"$", "g" );  
                                                var files = aFiles? aFiles : [];  
                                                var filterFunction = function(file)  
                                                {  
                                                return pattern.test ( file.name );  
                                                }  
                                                
                                                if ( bRecursive )  
                                                {  
                                                var foFiles = fo.getFiles();  
                                                while (  f = foFiles.shift() )  
                                                {  
                                                if ( f instanceof Folder )  
                                                {  
                                                if (includeFolder===true) files[ files.length ] = f;  
                                                
                                                this.getFiles ( f, aExtensions, true, files );  
                                                }  
                                                if ( f  instanceof File && pattern.test ( f.name ) && f.name!=".DS_Store" )   
                                                files[ files.length ]  = f;  
                                                }  
                                                
                                                return files;  
                                                }  
                                                
                                                else  
                                                {  
                                                return fo.getFiles ( filterFunction );  
                                                }  
                                                },  
                                                
                                                exportFile:function(file, opts, pngOpts) {  
                                                
                                                var doc = app.open ( file ), data = {ok:true};  
                                                
                                                
                                                try {  
                                                //doc.saveAs ( File ( file.parent+"/"+file.name.replace ( /\.eps?$/i, "" )+".pdf" ), opts);  
                                                doc.exportFile( File ( file.parent+"/"+file.name.replace ( /\.eps?$/i, "" )+".png" ), ExportType.PNG24, pngOpts );
                                                }  
                                                catch(err) {  
                                                data.ok = false;  
                                                data.message = "⚠ "+file.name+" couldn't exported cause :"+err.message ;  
                                                }  
                                                doc.close ( SaveOptions.DONOTSAVECHANGES );  
                                                
                                                return data;  
                                                },  
                                                
                                                
                                                log:function(msg) {  
                                                var f = File ( Folder.desktop+"/batchExport.txt" );  
                                                f.open('a');  
                                                f.writeln ( msg );  
                                                f.close();  
                                                },  
                                                
                                                getPNGOpts:function() {
                                                var opts = new ExportOptionsPNG24();
                                                opts.antiAliasing = true;
                                                opts.transparency = true;
                                                return opts;
                                               },
                                                
                                                getPDFOpts:function() {  
                                                var opts = new PDFSaveOptions();  
                                                opts.preserveEditability = true;  
                                                //whatever options you may want to set here  
                                                
                                                return opts;  
                                                }  
                                              }  
                                                
                                                
                                              var main = function() {  
                                                var fo = Folder.selectDialog("Please choose a folder"),  
                                                files,n = 0,  
                                                uip, result, pdfOpts, errors = [],
                                                pngOpts; 
                                                
                                                if ( !fo ) return;  
                                                
                                                files = Lib.getFiles ( fo, ["eps"], true );  
                                                
                                                n = files.length;  
                                                
                                                if ( !n ) {  
                                                alert("No files could be found");  
                                                return;  
                                                }  
                                                
                                                pdfOpts = Lib.getPDFOpts();  
                                                pngOpts = Lib.getPNGOpts();
                                                
                                                uip = app.userInteractionLevel;  
                                                app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  
                                                
                                                while (n--) {  
                                                result = Lib.exportFile ( files[n], pdfOpts, pngOpts );  
                                                !result.ok && errors.push ( result.message );  
                                                }  
                                                
                                                
                                                app.userInteractionLevel = uip;  
                                                errors.length && Lib.log ( errors.join("\r") );  
                                                alert( errors.length? "Some errors occured. Check log on Desktop" : "Everything worked smoothly" );  
                                                
                                              }  
                                                
                                                
                                              main(); 
                                              
                                              • 20. Re: Illustrator batch export to same folder
                                                miss-charlotte Level 1

                                                Fabulous! Works great. Good Karma coming your way Loic.