8 Replies Latest reply on Jun 21, 2017 4:52 AM by vinothr

    PNG creation with modified date

    tpk1982 Level 4

      HI,

       

      The following steps are doing.

       

      1) Open two indesign files. One is source and another one is final file.

       

      2) Based on modified date I need to create the png with file naming as _source and _final.

       

      mains();  
      function mains() {      
          var docSou = app.documents[0]; 
          var docFin = app.documents[1]; 
          var SouName = File(docSou.fullName);   
          var FinName = File(docFin.fullName);  
          var modifiedDate1= SouName.modified;  
          var modifiedDate2= FinName.modified;  
          
          mycheck1();
          
          function mycheck1(){
              if(modifiedDate1<modifiedDate2){
                  var docName =docSou.name.replace(/\.[^\.]+$/, '_source');
                  set_png_export_options();  
                  var file = new File("~/Desktop"+"/"+docName+".png");              
                  docSou.exportFile(ExportFormat.PNG_FORMAT, file);  
                  mycheck2();
                  exit();
              }
              else{
                  var docName =docFin.name.replace(/\.[^\.]+$/, '_final');
                  set_png_export_options();  
                  var file = new File("~/Desktop"+"/"+docName+".png");  
                  docFin.exportFile(ExportFormat.PNG_FORMAT, file);  
                  mycheck3();
                  exit();
              }
          }
      
      
      function mycheck2(){
          var docName =docFin.name.replace(/\.[^\.]+$/, '_final');
          var file = new File("~/Desktop"+"/"+docName+".png");  
          docFin.exportFile(ExportFormat.PNG_FORMAT, file);  
          }
      
      
      function mycheck3(){
          var docName =docSou.name.replace(/\.[^\.]+$/, '_source');
          var file = new File("~/Desktop"+"/"+docName+".png");              
          docSou.exportFile(ExportFormat.PNG_FORMAT, file);  
          }
      }  
        
      function set_png_export_options() {  
          with(app.pngExportPreferences) {  
              antiAlias = true;  
              embedColorProfile = true;  
              exportResolution =  1600;  
              exportingSpread = true;  
              PNGColorSpace = PNGColorSpaceEnum.RGB;  
              PNGExportRange = PNGExportRangeEnum.EXPORT_ALL;  
              PNGQuality = PNGQualityEnum.MAXIMUM;  
              simulateOverprint = false;  
              transparentBackground = false;  
              useDocumentBleeds = true;  
          }  
      }  
         
      

       

       

      But it always show the first document as _source.

       

      Could you please suggest where I am missing.

       

      Regards,

      K

        • 1. Re: PNG creation with modified date
          tpk1982 Level 4

          Hi,

           

          Any suggestion please, I know I am very close to the solution, but not able to find out that!!

           

          Thanks,

          K

          • 2. Re: PNG creation with modified date
            vinothr Level 3

            I am not sure what you are trying to achieve.

            But I am wondering why you are exporting twice.

             

             

            In the function mycheck1:

            Inside IF you export to file with "_source" name.

            Also you call mycheck2() which exports to file with "_final" name.

             

             

            Same in the else block also.

             

             

            So, essentially you seem to overwrite the file.

            Please check if you intend to do so.

            I believe with some traces you should be able to figure out.

            • 3. Re: PNG creation with modified date
              tpk1982 Level 4

              Hi,

               

              Thanks for your reply. If you see the first code, I am taking two indesign file. One is source and another one is final file. So I am exporting twice. So i not overriding.

               

              Thanks,

              K

              • 4. Re: PNG creation with modified date
                vinothr Level 3

                As I see the following code,

                 

                 

                var docSou = app.documents[0];  

                var docFin = app.documents[1]; 

                 

                docSou.name.replace(/\.[^\.]+$/, '_source');

                docFin.name.replace(/\.[^\.]+$/, '_final'); 

                 

                Whether it is the IF or the ELSE that is executing:

                The first document is always tagged as "_source"

                The second document as "_final"

                 

                Did you intend to do so above?

                Or did you intend to switch the source and dest doc as per modified file, which seems missing.

                1 person found this helpful
                • 5. Re: PNG creation with modified date
                  tpk1982 Level 4

                  Ye, but am taking the modifiedDate for each document and checking whether first document is old or not. If it is old means it tagged as source then it go to the mycheck2() function. This function will give the second document as Final.

                   

                  I am not sure I am explained clearly

                  • 6. Re: PNG creation with modified date
                    tpk1982 Level 4

                    I found the mistake I did.. here is final script working good..

                     

                    mains();   
                    function mains() {       
                        var docSou = app.documents[0]; 
                        var docFin = app.documents[1]; 
                        var SouName = File(docSou.fullName);   
                        var FinName = File(docFin.fullName);   
                        var modifiedDate1= SouName.modified;   
                        var modifiedDate2= FinName.modified;   
                         
                        mycheck1(); 
                         
                        function mycheck1(){ 
                            if(modifiedDate1<modifiedDate2){ 
                                var docName =docSou.name.replace(/\.[^\.]+$/, '_source'); 
                                set_png_export_options();   
                                var file = new File("~/Desktop"+"/"+docName+".png");               
                                docSou.exportFile(ExportFormat.PNG_FORMAT, file);   
                                mycheck2(); 
                                exit(); 
                            } 
                            else{ 
                                var docName =docSou.name.replace(/\.[^\.]+$/, '_final'); 
                                set_png_export_options();   
                                var file = new File("~/Desktop"+"/"+docName+".png");   
                                docSou.exportFile(ExportFormat.PNG_FORMAT, file);   
                                mycheck3(); 
                                exit(); 
                            } 
                        } 
                    
                    
                    function mycheck2(){ 
                        var docName =docFin.name.replace(/\.[^\.]+$/, '_final'); 
                        var file = new File("~/Desktop"+"/"+docName+".png");   
                        docFin.exportFile(ExportFormat.PNG_FORMAT, file);   
                        } 
                    
                    
                    function mycheck3(){ 
                        var docName =docFin.name.replace(/\.[^\.]+$/, '_source'); 
                        var file = new File("~/Desktop"+"/"+docName+".png");               
                        docFin.exportFile(ExportFormat.PNG_FORMAT, file);   
                        } 
                    }   
                       
                    function set_png_export_options() {   
                        with(app.pngExportPreferences) {   
                            antiAlias = true;   
                            embedColorProfile = true;   
                            exportResolution =  1600;   
                            exportingSpread = true;   
                            PNGColorSpace = PNGColorSpaceEnum.RGB;   
                            PNGExportRange = PNGExportRangeEnum.EXPORT_ALL;   
                            PNGQuality = PNGQualityEnum.MAXIMUM;   
                            simulateOverprint = false;   
                            transparentBackground = false;   
                            useDocumentBleeds = true;   
                        }   
                    }   
                    
                    • 7. Re: PNG creation with modified date
                      tpk1982 Level 4

                      Thanks for interest vinothr

                      • 8. Re: PNG creation with modified date
                        vinothr Level 3

                        That is what I meant. You didn't swap the source and final, which you have done now (in ELSE block):

                         

                        var docName =docFin.name.replace(/\.[^\.]+$/, '_final'); 

                         

                        TO

                         

                        var docName =docSou.name.replace(/\.[^\.]+$/, '_final');