4 Replies Latest reply on Aug 6, 2014 5:25 AM by AsOne

    Generate Log File for Dialog

    AsOne Level 1

      Hi All,


      I am generating the informations for dialog as a log file .txt format. Which means if the checkbox ticked, the log file will be give "checkbox1 - 01.   Check the ratio, sizes against job ticket and slug information" is ticked


      If checkbox not ticked,  the log file will be give "checkbox1 - 01.   Check the ratio, sizes against job ticket and slug information" is not ticked


      and also the "myText2" entry also need to generate in log file


      Can any one help on this... Help will be appreciated!



      var w = new Window ("dialog");

      var myGroup1 = w.add('panel', undefined, 'P&&G Check List');

      myGroup1.alignChildren = "left";

      var checkbox1 = myGroup1.add ("checkbox", undefined, "  01.   Check the ratio, sizes against job ticket and slug information");

      var checkbox2 = myGroup1.add ("checkbox", undefined, "  02.   Check images are linked");

      var checkbox3 = myGroup1.add ("checkbox", undefined, "  03.   Visually check the progression of KV/Model/CP images");

      var checkbox4 = myGroup1.add ("checkbox", undefined, "  04.   Visually check the progression of other elements like Logo and Bottle");

      var checkbox5 = myGroup1.add ("checkbox", undefined, "  05.   Check the placement of Language Tagging");

      var checkbox6 = myGroup1.add ("checkbox", undefined, "  06.   Ensure that all measurements are calculated based on Live area");

      var checkbox7 = myGroup1.add ("checkbox", undefined, "  07.   After resizing the KV image frame opened up to trim and bleed");

      var checkbox8 = myGroup1.add ("checkbox", undefined, "  08.   Fill Magenta if there is inadequate image");

      var checkbox9 = myGroup1.add ("checkbox", undefined, "  09.   Ensure the document has bleed, crop marks, gutter marks and slug information");

      var checkbox10 = myGroup1.add ("checkbox", undefined, "  10.   Ensure the final artwork is updated in the Server");

      var checkbox11 = myGroup1.add ("checkbox", undefined, "  11.   Enter time in CMD");

       

      var myGroup2 = w.add('panel', undefined, ' Operator Name');

      var myText2 = myGroup2.add("edittext", undefined, "");

      myText2.characters = 25;

      myGroup2.orientation = "left";

       

      var buttons = w.add ("group");

      buttons.add ("button", undefined, "Export PDF", {name: "ok"});

      buttons.add ("button", undefined, "Cancel");

      w.show ();

      //~ group();

      //~ if (myGroup1.alignChildren.value != true) {

      //~ alert ("yes")

      //~ }


      myDoc = app.activeDocument;

      w = [];


      //DESCRIPTION: Making TXT file

      myDoc = app.activeDocument;

      log1 = makeLogFile(app.activeDocument.name.split('.')[0], myDoc, true);

      log(log1, app.activeDocument.name);

      //~ log2 = makeLogFile("test",myDoc,false);

      //~ log(log2, "Text for log2 file");

      log1.execute();

      //~ log2.execute();

      function makeLogFile(aName, aDoc, deleteIt) {

      var logLoc; // path to folder that will hold log file

      try {

      logLoc = aDoc.filePath;

        } catch (e) {

          logLoc = getmyDoc().parent.fsName

        }

        var aFile = File(logLoc + "/" + aName + ".txt");

        if (deleteIt) {

          aFile.remove();

          return aFile;

        }

        var n = 1;

        while (aFile.exists) {

          aFile = File(logLoc + "/" + aName + String(n) + ".txt");

          n++

        }

        return aFile

      }

      function getScriptPath() {

          try {

          return app.activeScript;

        } catch(e) {

          return File(e.fileName);

        }

      }

      function log(aFile, message) {

      var today = new Date();

        if (!aFile.exists) {

          // make new log file

          aFile.open("w");

          aFile.write(String(today) + "\n");

          aFile.close();

        }

      }

       

      function log(aFile, message) {

        var text = w;

        if (!aFile.exists) {

          // make new log file

          aFile.open("w");

          aFile.write(message + "\n" + "\n" + String(w) + "\n");

          aFile.close();

       

      }

      //~   aFile.open("e");

      //~   aFile.seek(0,2);

      //~   aFile.write("\n" + message);

      //~   aFile.close();

      }

      //myDoc.close(SaveOptions.no);

       

      Thanks in Advance

      Steve

        • 1. Re: Generate Log File for Dialog
          Chinnadk Level 4

          Hi Steve,

           

          There are some mistakes on your code.

           

          1. function 'getmyDoc' is used but not created.
          2. fucntion 'getScriptPath' is created but not used.(Anyway this will not give error)
          3. function 'log' has defined two times with same length of parameter.

           

          etc...

           

          Here I modified your code. Try this.

           

          var w = new Window ("dialog");
          var myGroup1 = w.add('panel', undefined, 'P&&G Check List');
          myGroup1.alignChildren = "left";
          var checkbox1 = myGroup1.add ("checkbox", undefined, "  01.  Check the ratio, sizes against job ticket and slug information");
          var checkbox2 = myGroup1.add ("checkbox", undefined, "  02.  Check images are linked");
          var checkbox3 = myGroup1.add ("checkbox", undefined, "  03.  Visually check the progression of KV/Model/CP images");
          var checkbox4 = myGroup1.add ("checkbox", undefined, "  04.  Visually check the progression of other elements like Logo and Bottle");
          var checkbox5 = myGroup1.add ("checkbox", undefined, "  05.  Check the placement of Language Tagging");
          var checkbox6 = myGroup1.add ("checkbox", undefined, "  06.  Ensure that all measurements are calculated based on Live area");
          var checkbox7 = myGroup1.add ("checkbox", undefined, "  07.  After resizing the KV image frame opened up to trim and bleed");
          var checkbox8 = myGroup1.add ("checkbox", undefined, "  08.  Fill Magenta if there is inadequate image");
          var checkbox9 = myGroup1.add ("checkbox", undefined, "  09.  Ensure the document has bleed, crop marks, gutter marks and slug information");
          var checkbox10 = myGroup1.add ("checkbox", undefined, "  10.  Ensure the final artwork is updated in the Server");
          var checkbox11 = myGroup1.add ("checkbox", undefined, "  11.  Enter time in CMD");
          var myGroup2 = w.add('panel', undefined, ' Operator Name');
          var myText2 = myGroup2.add("edittext", undefined, "");
          myText2.characters = 25;
          myGroup2.orientation = "left";
          var buttons = w.add ("group");
          buttons.add ("button", undefined, "Export PDF", {name: "ok"});
          buttons.add ("button", undefined, "Cancel");
          w.show ();
          myDoc = app.activeDocument;
          log1 = makeLogFile(app.activeDocument.name.split('.')[0], myDoc, true);
          log(log1, app.activeDocument.name);
          log1.execute();
          function makeLogFile(aName, aDoc, deleteIt)
          {
              var logLoc = "";
              try
              {
                  logLoc = aDoc.filePath;
                  } catch (e) {}
              var aFile = File(logLoc + "/" + aName + ".txt");
              var n = 1;
              while (aFile.exists)
              {
                  aFile = File(logLoc + "/" + aName + String(n) + ".txt");
                  n++;
                  }
              return aFile
              }
          function log(aFile, message)
          {
              var text = w;
              var rep = "";
              if (!aFile.exists)
              {
                  aFile.open("w");
                  var today = new Date();
                  rep += String(today) + "\n";
                  rep += message + "\n" + "\n\n";
                  for(var i =0;i<myGroup1.children.length;i++)
                  {
                          if(myGroup1.children[i].value == true)
                          {
                                  rep += "checkbox - " + parseInt(i+1) + " " + myGroup1.children[i].text + " is ticked\r";
                              }
                          else
                          {
                                  rep += "checkbox - " + parseInt(i+1) + " " + myGroup1.children[i].text + " is not ticked\r";
                              }
                      }
                  aFile.write(rep);
                  aFile.close();
                  }
              }
          

           

          Regards,

          Chinna

          • 2. Re: Generate Log File for Dialog
            AsOne Level 1

            Hi Chinna,

             

            You are amassing, works super. Thank you so much to modified.

             

            Only one thing is not generating in log file

            var myText2 = myGroup2.add("edittext", undefined, "");

             

            Thanks

            Steve

            • 3. Re: Generate Log File for Dialog
              Chinnadk Level 4

              Just add this

              rep +="\n\n" + myText2.text;

               

              before this

              aFile.write(rep);

              • 4. Re: Generate Log File for Dialog
                AsOne Level 1

                Hi Chinna,

                 

                You are super fantastic in JS. It works good. THANKS LOT.

                 

                Thanks

                Steve