3 Replies Latest reply on Feb 20, 2014 1:51 PM by try67

    Looping error code

    Doc_45

      The following code generates an error when checking to see if a document exists. I have highlighted the section with stars where it is falling over. This code worked for years then stopped, then 6 months ago started again. I assumed Adobe playing around with security issues.

       

      Any clues would be appreciated, as I am a newby and taught myself this code.

       

       

      function GAddDP()

      {

           var aFiles = new Array("_Map_A.pdf","_Map_B.pdf","_Map_C.pdf","_Map_D.pdf","_Map_E.pdf","_Map_F.pdf","_Dem o.pdf","_Bus.pdf","_Spend.pdf");

           var cnewfile = new Array(8)

       

           var aPathComps = this.path.split("/");               // Path

           var myFileName = aPathComps.pop();               // Filename

           var fileNmRoot = myFileName.split(".").shift();          // Root Filename

           var strNewPath = aPathComps.join("/");               // Append path to File to Insert

       

      for ( var i=0; i < aFiles.length; i++) {               // Loop through Array

           var fileNmNew = fileNmRoot + aFiles               // File to Insert
           //console.println(fileNmNew);
           cnewfile = strNewPath + "/" + fileNmNew          // Combine All
           //console.println(cnewfile);
           }
      //**************************************************************
      for ( var i=0; i < cnewfile.length; i++) {               // Loop through the list of filenames
           var nfileexists = 1;
           try{
           var otherDoc = app.openDoc(cnewfile);          // Test if File exists
           }catch(e){
              nfileexists = 0;                         // Catch the errror if it doesnt
           }
      //**************************************************************
      if (nfileexists > 0)
           {
           otherDoc.closeDoc();                              // If it exists close it
           this.insertPages({nPage:this.numPages-1,cPath:cnewfile});     // Insert the document if it exists
           }
           }
      //*** Front Cover
           var fileNmNew2 = fileNmRoot + "_Cover.pdf"          // File to Insert
           var cnewfile2 = strNewPath + "/" + fileNmNew2          // Combine All
      try{
           var nfileexists = 1
           var otherDoc = app.openDoc(cnewfile2);
           }catch(e){
              nfileexists = 0;
           }
      if (nfileexists > 0)
           {
           otherDoc.closeDoc();
           this.insertPages({nPage:-1,cPath:cnewfile2,nStart: 0 });
           }
      app.alert({cMsg: "     Data Pack Append Completed !",cTitle: "Data Packs"});
      }

      Thanx Mark

        • 1. Re: Looping error code
          try67 MVP & Adobe Community Professional

          What is the error message, exactly?

          • 2. Re: Looping error code
            Doc_45 Level 1

            Gilad,

             

            Not so much an error message as the debugger window would appear and the process stop.

            It happens when I run the program but do not have ecery document available

            eg: Map_A, Map_B, Map_C,Demo,Bus - It will fall over when it cannot find Map_d.

             

            As I said it used to work, and I have not adjusted the code so it must be some security issue change from adobe, I think

             

            Regards Doc_45

            • 3. Re: Looping error code
              try67 MVP & Adobe Community Professional

              No, that means there is an error but your try-catch clauses are making it invisible because they're not printing the error message to the console.

              My guess is that that file is not disclosed, which causes an error when you try to access the variable that it returns, but it's null. You should either remove the try-catch blocks or at least add a command to them that prints the error details. Otherwise you're fishing in the dark for the error...