5 Replies Latest reply on Nov 9, 2016 6:49 AM by BEGINNER_X

    First Read and later write in .csv file

    BEGINNER_X Level 3

      Hi All,

       

      Request is below, I need to get an idea for a big concept

       

      1. Open the Indesign document by read the .csv file

       

      2. After open the document, if Missing Font is available, then the Report write it as FAIL

       

      3. Is it possible reading and writing in same .csv

       

      Read .csv

       

      Screen Shot 2016-11-08 at 12.36.09.png

       

      Write .csv:

       

      Screen Shot 2016-11-08 at 12.36.15.png

       

      Sample Code is below:

       

      var txtFile=File(Folder.desktop + "/somefile.csv");
      if(File(Folder.desktop + "/test.txt").exists ==false)
      {
          var txtFile=new File(Folder.desktop + "/somefile.csv");
      }
      
      txtFile.open("r")
       while(txtFile.eof == false)
      {
              var myFind = txtFile.readln();
              alert("myFind: " + myFind)
              var myLine = myFind.split(",");
              alert("myLine Comma: " + myLine)
              
              //------------Missing Font Condition Code Here-------------
              
      
              txtFile.open("e");
              txtFile.seek(0, 2);
              txtFile.write(" FAIL");
              txtFile.close();
              }
      

       

       

      Thanks in Advance

      Siraj

        • 1. Re: First Read and later write in .csv file
          tpk1982 Level 4

          Yes it is possible to read and writing in same .csv

          • 2. Re: First Read and later write in .csv file
            Trevorׅ Adobe Community Professional

            Hi Siraj

             

            I'm not too sure what you want to do.

            It sounds like you want

            • read the csv
            • get indesign to open the documents and check for fonts
            • write back to the csv file

             

            If the file is not too long it's should be very simple to just read the entire csv, look at the files and then rewrite the the whole csv.

             

            HTH

             

            Trevor

            • 3. Re: First Read and later write in .csv file
              BEGINNER_X Level 3

              Thanks Trevor/Karthik,

               

              Tried the below code using seek(0,2), but not works

               

              seek(0,2) should break the loop and create the FAIL report in the EOF of .csv only

               

              var csvFile=File(Folder.desktop + "/somefile.csv");
              
              csvFile.open("r")
               while(csvFile.eof == false)
              {
                      var myFind = csvFile.readln();
                      var myLine = myFind.split(",");
              
                     var myTemp_Path = myLine[0];
                     alert("myTemp_Path: " + myTemp_Path)
                     
                     app.open(File(myTemp_Path))
                     
                     //Missing Font Concept below
                     var _missingFont_Check = 0;
                      var myUsedFonts = app.activeDocument.fonts; 
                      for (var i = 0; i < myUsedFonts.length; i++) 
                      { 
                      if (myUsedFonts[i].status != "1718831470") 
                      { 
                          _missingFont_Check = 1;
                          } 
                      } 
              
                      //-----------------Help needed for below lines------------------
                      if(_missingFont_Check == 1)
                      {
                          alert("Document having missing font");
                         // exit(0);
                         csvFile.open("e"); 
                          csvFile.seek(0, 2);     //Suspect seek (0,2)
                          csvFile.write( "\tFAIL");      
                          csvFile.close()
                          }
                    }
              

               

              Before running the script,

               

              Screen Shot 2016-11-08 at 14.57.33.png

               

              After running the script,

               

              Actually "RRR.indd" file having missing font, by using the above code loop breaks and the report created in last row(abcd.indd).

               

              Screen Shot 2016-11-08 at 14.57.48.png

               

              Thanks in Advance

              Siraj

              • 4. Re: First Read and later write in .csv file
                Trevorׅ Adobe Community Professional

                I had something more like the below in mind

                // Not tested even one time
                // in a very lazy mode
                var csvData, csvFile, l, doc,  myTemp_Path;
                csvFile = File(Folder.desktop + "/somefile.csv");
                csvFile.open("r");
                csvData = csvFile.read().split('\n');
                csvFile.close();
                l = csvData.length;
                while (l--){
                  myTemp_Path = csvData[l].split(',')[0];
                  doc = app.open(File(myTemp_Path));
                  // Very lazy line, sorry
                  csvData[l] = (doc.fonts.everyItem().status.toString().replace(/INSTALLED|\,/g,'').length) ?
                    myTemp_Path + ', Fail' : myTemp_Path;
                }
                csvFile.open("w").write(csvData.join('\n')).csvFile.close();
                
                • 5. Re: First Read and later write in .csv file
                  BEGINNER_X Level 3

                  Thank you Trevor,

                   

                  working fine after a slight modifications...

                   

                  Again thanks a lot.