36 Replies Latest reply: Jul 17, 2013 8:35 AM by John Kriho RSS

    Batch export grouped items as jpeg?

    tlcano Community Member

      Hi there-

       

      We have decided that it's time to switch to InDesign; we're paying for it as part of CS4 anyway (we will be upgrading when the next update is announced), and Quark just isn't doing what we need anymore. We're trying to take care of a few things before just jumping in, and I've found an issue with one of our tasks.

       

      Our files are made up of anywhere from 5-15 individual ads, which are printed in a strip. Each of those individual ads needs to be exported as a jpeg so that it can be placed on our company's website. In Quark, we would run Gluon's XPress Image Pro, and it would find each grouped object and export it, but Gluon does not offer an ID version of this software. I was hoping that there would be some nifty little built-in trick that would do this for me, but the general forum seemed to think otherwise. Bob Levine suggested I pop over here and see if I could find a scripting solution. I'm pretty new to scripting, but if you've got any advice, I'm all ears.

       

      Thanks!

        • 1. Re: Batch export grouped items as jpeg?
          Muppet Mark Community Member

          As I said in that thread that script may help you with this… I feel I should help… This should give you a starter… It will just dump the JPEGS on your desktop for now…

           

           

          #target indesign
          
          function groupsToJPEGs() {
            
                    if ( app.documents.length == 0 ) { return; }
            
                    var i, doc, grps, prfs, expFile;
          
                    doc = app.activeDocument;
            
                    prfs = app.jpegExportPreferences;
          
                    prfs.antiAlias = true;
                    prfs.embedColorProfile = true;
                    prfs.exportResolution = 300;
                    prfs.jpegColorSpace = JpegColorSpaceEnum.RGB;
                    prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                    prfs.simulateOverprint = true;
            
                    grps = doc.groups;
          
                    for ( i = 0; i < grps.length; i++ ) {
          
                              expFile = File( Folder.desktop + '/Ad_Group_' + i + '.jpg' );
          
                              doc.groups[i].exportFile( ExportFormat.JPG, expFile, false );
          
                    };
          
          };
          
          groupsToJPEGs();
          
          
          • 2. Re: Batch export grouped items as jpeg?
            tlcano Community Member

            Thank you for the help! I was finally able to give this a shot, but I got an error message: 'unexpected end of line, etc. but found identifier.' Any suggestions?

            • 3. Re: Batch export grouped items as jpeg?
              [Jongware] MVP

              Exact line number and error message?

              • 4. Re: Batch export grouped items as jpeg?
                tlcano Community Member

                That was the entire message. I used the script posted above, and that is the exact message I received.

                • 5. Re: Batch export grouped items as jpeg?
                  Muppet Mark Community Member

                  Hum, how did you go about saving it? I just C&P the above into a new ESTK window and alt+comm+k it say it OK… comm+r and ooops… I've got the wrong doc open now ( who's the muppet )… A trip to the trash for that lot…

                   

                  Screen shot 2012-03-01 at 12.59.26.png

                  • 6. Re: Batch export grouped items as jpeg?
                    tlcano Community Member

                    Hi there-

                     

                    Thanks for the script advice! I've finally been able to clear my schedule enough to give this some serious attention, and I'm stumped. I hit comm+r and it stops at the prfs.antiAlias = true; line. If I continue past that, it stops at each of the other prfs lines, and then I get no result. Any more advice you can offer, I'm listening. Please help if you can- my boss is threatening not to switch to ID because this one workflow (which is a fraction of our job) is an issue. D:

                     

                    Thanks again!

                    • 7. Re: Batch export grouped items as jpeg?
                      Muppet Mark Community Member

                      If your boss is not wanting to pay for the switch to ID ( based on this snippet ) Then he/she is a bigger muppet than me… ( dam and blast there goes my commission ) I've C&P back to the toolkit twice now and it works?

                      • 8. Re: Batch export grouped items as jpeg?
                        tlcano Community Member

                        Yeah, there's a lot of backstory there. I just work with what I have, and it's seriously cramping my style. My workflow isn't... well, flowing, and it's largely to do with the Quark to Adobe part. They're not playing nice, and I'm kind of stuck.

                         

                        Do you think it could have something to do with the grouped objects themselves? I'm a total neophyte when it comes to scripting, so that's just a guess, but it's all I can think of. Let's use the example below... these are the sort of ads that must be converted, and there are anywhere from 1-15 of them on a store. When I go to run the script, it highlights the line in orange and the error line says 'Object does not support the property or method 'antiAlias' (included here in case the jpeg is unreadable). If I skip that step, it gives the same message for each subsequent preference.

                        Screen Shot 2012-04-17 at 2.13.00 PM.png

                         

                        Any ideas? I'm so sorry, I'm having to learn as I go! Thank you so much!!!

                        • 9. Re: Batch export grouped items as jpeg?
                          Muppet Mark Community Member

                          CS4 its different set of properties for the export… You may not get all the options you want in that version of ID but it shold only take a moment to make something work…

                          I don't have CS4 so I can't test this… The options are limited… Now there's a reason for an upgrade commi$$ion back on…

                           

                          #target indesign
                          
                          function groupsToJPEGs() {
                            
                                    if ( app.documents.length == 0 ) { return; }
                            
                                    var i, doc, grps, prfs, expFile;
                          
                                    doc = app.activeDocument;
                            
                                    prfs = app.jpegExportPreferences;
                          
                                    prfs.resolution = 300;
                                    prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                    prfs.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
                            
                                    grps = doc.groups;
                          
                                    for ( i = 0; i < grps.length; i++ ) {
                          
                                              expFile = File( Folder.desktop + '/Ad_Group_' + i + '.jpg' );
                          
                                              doc.groups[i].exportFile( ExportFormat.JPG, expFile, false );
                          
                                    };
                          
                          };
                          
                          groupsToJPEGs();
                          
                          
                          • 10. Re: Batch export grouped items as jpeg?
                            tlcano Community Member

                            Oh my gosh, it worked!!!! I can't tell you how awesome that is! Do you know how I could fine-tune it to direct me to a specific folder (maybe a batch folder on the desktop)? I'd like the jpegs to retain the name of the original file as well; for example, if the store is Bakers 311, could I have them be named Bakers311_1.jpg, etc.?

                             

                            Thank you, thank you, thank you!!!

                            • 11. Re: Batch export grouped items as jpeg?
                              Muppet Mark Community Member

                              Yes, yes, yes script can be set up ( fine tuned ) to do all sorts of things and much more so in ID over Quark… My fault I didn't read the your post properly ( hey your the first person to be behind me on the upgrade trail  ). I just presumed CS5 or greater… 3 years I nagged for upgrades ( and I can grumble with the best  )

                              • 12. Re: Batch export grouped items as jpeg?
                                tlcano Community Member

                                Working on it! If this works, we'll be upgrading to CS6 as soon as it's released.

                                 

                                So I need to refine the script a bit- would the changes below do what I asked (i.e., move the files to my desktop/Batch folder and save them as the file name + #? Also, is there a way I could have it process multiple stores at once? Thanks so much!

                                 

                                #target indesign

                                function groupsToJPEGs() {
                                 
                                          if ( app.documents.length == 0 ) { return; }
                                 
                                          var i, doc, grps, prfs, expFile;

                                          doc = app.activeDocument;
                                 
                                          prfs = app.jpegExportPreferences;

                                          prfs.resolution = 200;
                                          prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                          prfs.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
                                 
                                          grps = doc.groups;

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

                                                    expFile = File( Folder.desktop/Batch + '/filename' + i + '.jpg' );

                                                    doc.groups[i].exportFile( ExportFormat.JPG, expFile, false );

                                          };

                                };

                                groupsToJPEGs();

                                • 13. Re: Batch export grouped items as jpeg?
                                  tlcano Community Member

                                  Never mind. That brought back THIS error:

                                   

                                  Screen Shot 2012-04-18 at 4.30.08 PM.png

                                   

                                  I told you I was hopeless!

                                  • 14. Re: Batch export grouped items as jpeg?
                                    [Jongware] MVP

                                    expFile = File( Folder.desktop/Batch + '/filename' + i + '.jpg' );

                                     

                                    Your notation for getting the Folder is not correct.

                                     

                                    Folder.desktop is a valid object, and it returns a Folder object (which can be treated as a regular text string). You cannot just paste "/Batch" right after it -- that's Bad Syntax. You also add your variable 'filename' as a literal string -- between quotes. That only adds the exact string "filename" (uh, but then without those quotes) to the path.

                                     

                                    Try this:

                                     

                                    expFile = File( Folder.desktop+ '/Batch/' + filename + i + '.jpg' );

                                     

                                    -- it will build up the file name out of the individual parts "Desktop Folder Path", "The Literal String 'Batch'", "the value of the variable filename", "the value of 'i'", and, closing down, "the literal string 'dot jpg'".

                                    • 15. Re: Batch export grouped items as jpeg?
                                      tlcano Community Member

                                      Thank you! One problem, though- it brought back the error "filename is undefined."

                                      • 16. Re: Batch export grouped items as jpeg?
                                        Muppet Mark Community Member

                                        Try this it works with my CS5 and should cover your CS4 too… A bit long winded… Of cause you may need to pop back here for CS6 where things may or may not chane again…

                                        #target indesign
                                        
                                        function groupsToJPEGs() {
                                          
                                            if ( app.documents.length == 0 ) { return; }
                                          
                                            var i, doc, grps, prfs, expFile, saveFold;
                                            
                                            saveFold = Folder( Folder.desktop + '/Batch' );
                                            
                                            if ( ! saveFold.exists ) { saveFold.create(); }
                                        
                                            doc = app.activeDocument;
                                          
                                            prfs = app.jpegExportPreferences;
                                            
                                            if ( parseInt( app.version ) == 7 ) {
                                        
                                                prfs.antiAlias = true;
                                                prfs.embedColorProfile = true;
                                                prfs.exportResolution = 300;
                                                prfs.jpegColorSpace = JpegColorSpaceEnum.RGB;
                                                prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                                prfs.simulateOverprint = true;
                                            
                                            };
                                        
                                            if ( parseInt( app.version ) == 6 ) {
                                        
                                                  prfs.resolution = 200;
                                                  prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                                  prfs.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
                                            
                                            };
                                          
                                            grps = doc.groups;
                                        
                                            for ( i = 0; i < grps.length; i++ ) {
                                        
                                                expFile = File( saveFold + '/'+ doc.name + '_' + i + '.jpg' );
                                        
                                                doc.groups[i].exportFile( ExportFormat.JPG, expFile, false );
                                        
                                            };
                                        
                                        };
                                        
                                        groupsToJPEGs();
                                        
                                        • 17. Re: Batch export grouped items as jpeg?
                                          tlcano Community Member

                                          That worked! Two more questions, and I'll stop bothering you (until CS6 comes out, at least)... is it possible to apply the action to all open documents? And is it possible to start the numbering at 1 instead of zero?

                                           

                                          You are awesome!

                                          • 18. Re: Batch export grouped items as jpeg?
                                            tlcano Community Member

                                            Whoa, another problem just popped up! Some of these stores will have up to 15 separate ads, and each will need to be processed, but only the first 5 were made. I didn't see any errors pop up. Any suggestions?

                                            • 19. Re: Batch export grouped items as jpeg?
                                              Muppet Mark Community Member

                                              What does this tell you…?

                                               

                                              alert( app.activeDocument.groups.length )
                                              

                                               

                                               

                                              expFile = File( saveFold + '/'+ doc.name + '_' + ( i + 1 ) + '.jpg' );
                                              

                                               

                                              Should sort the zero base i

                                              • 20. Re: Batch export grouped items as jpeg?
                                                tlcano Community Member

                                                Does it get pasted just like that? If so, each time it processes a grouped object, it pops up a message that says "5".

                                                • 21. Re: Batch export grouped items as jpeg?
                                                  Muppet Mark Community Member

                                                  Just run the TOP snippet as it is a one line script…

                                                   

                                                  The second snippet is a replacemnet line… See the ( i + 1 ) has been added in…

                                                   

                                                   

                                                  • 22. Re: Batch export grouped items as jpeg?
                                                    tlcano Community Member

                                                    ::facepalm:: the artist hadn't put 7 of his ads in a group! Gah!

                                                     

                                                    That totally worked!!!! Problem solved, happy boss! You are terrific!

                                                     

                                                    I'll leave you alone until 6 comes out then. If you think of a solution to running this as a process on multiple stores, let me know. Otherwise, thank you, thank you, thank you!!!

                                                    • 23. Re: Batch export grouped items as jpeg?
                                                      tlcano Community Member

                                                      Hello-

                                                       

                                                      As promised, I left you alone until CS6 came out. Can you help me adjust the script for the new version? Also, do you know of a way to make the script work on multiple stores at once? We could certainly work around it, but it would be way easier (and probably more idiot-proof) if we could just have it run the script on every item in a particular folder, or a batch of opened stores (preferably the former).

                                                       

                                                      Thank you so much!

                                                       

                                                      T

                                                      • 24. Re: Batch export grouped items as jpeg?
                                                        VanithaAllwin Community Member

                                                        Hi,

                                                         

                                                        The same way as we export selection to jpeg, is it possible to convert the selection to swf? Please help.

                                                         

                                                        Thanks,

                                                        Vanitha Allwin

                                                        • 25. Re: Batch export grouped items as jpeg?
                                                          Vamitul Community Member

                                                          Here it is modified to export all opened documents. Don't have CS6 yet, but it shoud work.

                                                          #target indesign
                                                          var saveFold;  
                                                            function main(){    
                                                               saveFold = Folder( Folder.desktop + '/Batch' );
                                                                  if ( ! saveFold.exists ) { saveFold.create(); }
                                                              var prfs;
                                                          
                                                              prfs = app.jpegExportPreferences;
                                                          
                                                              if ( parseInt( app.version ) >= 7 ) {
                                                          
                                                                  prfs.antiAlias = true;
                                                                  prfs.embedColorProfile = true;
                                                                  prfs.exportResolution = 300;
                                                                  prfs.jpegColorSpace = JpegColorSpaceEnum.RGB;
                                                                  prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                                                  prfs.simulateOverprint = true;
                                                          
                                                              };
                                                          
                                                              if ( parseInt( app.version ) == 6 ) {
                                                          
                                                                    prfs.resolution = 200;
                                                                    prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                                                    prfs.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
                                                          
                                                              };
                                                             for (var j=0; j<app.documents.length;j++){
                                                          groupsToJPEGs (app.documents[j]);
                                                          }
                                                          }
                                                          function groupsToJPEGs(doc) {
                                                                var i, grps, expFile;
                                                          
                                                          
                                                              grps = doc.groups;
                                                          
                                                              for ( i = 0; i < grps.length; i++ ) {
                                                          
                                                                  expFile = File( saveFold + '/'+ doc.name + '_' + ( i + 1 ) + '.jpg' ); 
                                                                  doc.groups[i].exportFile( ExportFormat.JPG, expFile, false );
                                                          
                                                              };
                                                          
                                                          };
                                                          
                                                          main();
                                                          
                                                          • 26. Re: Batch export grouped items as jpeg?
                                                            Vamitul Community Member


                                                            VanithaAllwin wrote:

                                                             

                                                            Hi,

                                                             

                                                            The same way as we export selection to jpeg, is it possible to convert the selection to swf? Please help.

                                                             

                                                            Thanks,

                                                            Vanitha Allwin

                                                            Tell me the preferences you need for wxporting the swf, and i hope i can help.

                                                            • 27. Re: Batch export grouped items as jpeg?
                                                              VanithaAllwin Community Member

                                                                 The swf preferences are given below except swf with and height. The swf width and height should match the selection.

                                                               

                                                                   app.swfExportPreferences.fitMethod  = FitMethodSettings.fitGivenScalePercentage;

                                                                  app.swfExportPreferences.fitOption = FitDimension.fit1024x768;

                                                                  app.swfExportPreferences.fitScale = 100;

                                                                  app.swfExportPreferences.pageRange = range;

                                                                  app.swfExportPreferences.dynamicDocumentExportReaderSpreads = 0;

                                                                  app.swfExportPreferences.rasterizePages = false;

                                                                  app.swfExportPreferences.generateHTML = false;

                                                                  app.swfExportPreferences.viewSWFAfterExporting = false;

                                                                  app.swfExportPreferences.textExportPolicy = DynamicDocumentsTextExportPolicy.live;

                                                                  app.swfExportPreferences.includeInteractivePageCurl = true;

                                                                  app.swfExportPreferences.rasterCompression = RasterCompressionOptions.losslessCompression;

                                                                  app.swfExportPreferences.jpegQualityOptions = DynamicDocumentsJPEGQualityOptions.maximum;

                                                                  app.swfExportPreferences.curveQuality = SWFCurveQualityValue.maximum;

                                                                  app.swfExportPreferences.rasterResolution = 100;

                                                               

                                                              Thanks,

                                                              Vanitha Allwin

                                                              • 28. Re: Batch export grouped items as jpeg?
                                                                Vamitul Community Member

                                                                then replace the line:

                                                                    prfs = app.jpegExportPreferences;

                                                                with

                                                                    prfs = app.swfExportPreferences;

                                                                 

                                                                and

                                                                          prfs.antiAlias = true;
                                                                        prfs.embedColorProfile = true;
                                                                        prfs.exportResolution = 300;
                                                                        prfs.jpegColorSpace = JpegColorSpaceEnum.RGB;
                                                                        prfs.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                                                                        prfs.simulateOverprint = true;
                                                                with your preferences.

                                                                should work.

                                                                • 29. Re: Batch export grouped items as jpeg?
                                                                  VanithaAllwin Community Member

                                                                  The above setting shows error saying "preferences doesn't have antiAlias property". Eventhough i have used correct swf preferences setting, the whole page has been exported as swf instead of only the selection. Please help. I need this urgently.

                                                                  • 30. Re: Batch export grouped items as jpeg?
                                                                    Vamitul Community Member

                                                                    Hello.

                                                                     

                                                                    here is the full script. I made a few changes. Hope it works for you.

                                                                     

                                                                    #target indesign
                                                                    var saveFold;  
                                                                      function main(){    
                                                                         saveFold = Folder( Folder.desktop + '/Batch' );
                                                                            if ( ! saveFold.exists ) { saveFold.create(); }
                                                                    
                                                                       app.documents[0].groups.firstItem().select();
                                                                    
                                                                      //  app.swfExportPreferences.fitMethod  = FitMethodSettings.fitGivenScalePercentage;
                                                                    //    app.swfExportPreferences.fitOption = FitDimension.fit1024x768;
                                                                        app.swfExportPreferences.fitScale = 100;
                                                                      //  app.swfExportPreferences.pageRange = "Selection";
                                                                        app.swfExportPreferences.dynamicDocumentExportReaderSpreads = 0;
                                                                        app.swfExportPreferences.rasterizePages = false;
                                                                        app.swfExportPreferences.generateHTML = false;
                                                                        app.swfExportPreferences.viewSWFAfterExporting = false;
                                                                        app.swfExportPreferences.textExportPolicy = DynamicDocumentsTextExportPolicy.live;
                                                                        //app.swfExportPreferences.includeInteractivePageCurl = true;
                                                                        app.swfExportPreferences.rasterCompression = RasterCompressionOptions.losslessCompression;
                                                                        app.swfExportPreferences.jpegQualityOptions = DynamicDocumentsJPEGQualityOptions.maximum;
                                                                        app.swfExportPreferences.curveQuality = SWFCurveQualityValue.maximum;
                                                                        app.swfExportPreferences.rasterResolution = 100; 
                                                                    
                                                                     for (var j=0; j<app.documents.length;j++){
                                                                    groupsToJPEGs (app.documents[j]);
                                                                    }
                                                                    }
                                                                    function groupsToJPEGs(doc) {
                                                                          var i, grps, expFile;
                                                                    
                                                                    
                                                                        grps = doc.groups;
                                                                    
                                                                        for ( i = 0; i < grps.length; i++ ) {
                                                                    
                                                                            expFile = File( saveFold + '/'+ doc.name + '_' + ( i + 1 ) + '.swf' ); 
                                                                            doc.groups[i].select();
                                                                            doc.groups[i].exportFile( ExportFormat.SWF, expFile, false );
                                                                    
                                                                        };
                                                                    
                                                                    };
                                                                    
                                                                    main();
                                                                    

                                                                     

                                                                     

                                                                    ps. Anyone can tell me how can i make the "advanced editor" as default for replies in this forum?

                                                                     

                                                                    Message was edited by: Vamitul

                                                                    • 31. Re: Batch export grouped items as jpeg?
                                                                      Laubender MVP

                                                                      ps. Anyone can tell me how can i make the "advanced editor" as default for replies in this forum?

                                                                       

                                                                      @Vatimul – as the following screen grab shows, "Use advanced editor" is back when replying (above the upper right corner of the edit field):

                                                                       

                                                                      Bildschirmfoto 2012-06-20 um 08.38.07.png

                                                                       

                                                                      If you cannot see it, maybe you could refresh the webpage with cmd + shift + r in the browser. Maybe it's your browser. I'm using Firefox on Mac OSX 10.6.8.

                                                                       

                                                                      Uwe

                                                                       

                                                                      Message was edited by: Laubender

                                                                      • 32. Re: Batch export grouped items as jpeg?
                                                                        VanithaAllwin Community Member

                                                                        I changed the setting as you mentioned. The whole page has been exported as swf instead of only the selection.

                                                                        • 33. Re: Batch export grouped items as jpeg?
                                                                          Vamitul Community Member

                                                                          did you use the script i just posted above?

                                                                          you might need to manualy export one group before running the scrip.

                                                                          • 34. Re: Batch export grouped items as jpeg?
                                                                            VanithaAllwin Community Member

                                                                            Yes. It doesn't seem to be working.

                                                                            • 35. Re: Batch export grouped items as jpeg?
                                                                              tlcano Community Member

                                                                              Hi there-

                                                                               

                                                                              I tried to run the script to export all opened documents, but I keep getting the error "Target Adobe InDesign CS4 (6.0) provides no engine for debugging. I have switched the link to InDesign CS6, but it switches back to CS4 whenever I try to run the script. Any suggestions?

                                                                               

                                                                              Thanks!

                                                                              T

                                                                              • 36. Re: Batch export grouped items as jpeg?
                                                                                John Kriho

                                                                                Does this process work with nested groups (groups that contain other groups)?

                                                                                 

                                                                                How do you locate the outermost group?