6 Replies Latest reply on May 1, 2014 7:57 AM by 4everJang

    Output function (results to a file) in Extendscript

    klk_nc

      When I check a script I use the alert to see if the code is working, such as "Current tag is body".

      Is there a function that outputs alert results to a file? For example, a way to send to a file all

      of the paragraph tags that are used in a document. (The actual code could be a loop). I could

      use this as a start to produce what I really want, an array of all the valid tags, and then print to a file

      a list of all the "rogue" tags that are not in the valid list

        • 1. Re: Output function (results to a file) in Extendscript
          4everJang Level 3

          Check the JavaScript Tools Guide for details about the File object. Basically, it works more or less like this:

           

          var oFile = new File ( /* full path name as text string */ );

           

          oFile.open( "w" );     /* use "a" to append, "w" to remove existing text.

           

          oFile.writeln ( "Whatever you want to write in there" );

           

          oFile.close (  );

           

           

          Ciao

           

          Jang

          • 2. Re: Output function (results to a file) in Extendscript
            klk_nc Level 1

            Here's the code I have, but the Extendscript debugger says oFile.open is not a function, is this only for javascript?

             

            Thanks,

             

            Keith

             

            function processDoc (doc) {

             

                    //Process the paragraphs and tables in the main document flow

             

                    var textList, count = 0, i = 0, tbl = 0, pgf = 0;

                    var oFile = "c:\myname\tags-list.txt";

             

                    // Turn off the document display to speed the script and

                    // prevent screen flicker.

                    if (app.Displaying == 1) {

                    app.Displaying = 0;

                    }

                   

                    //Process each top-level paragraph in document

                   

                    oFile.open("a");

                    pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

             

                    while (pgf.ObjectValid()) {

                   

                //!!    applyNewPgfFmt(pgf,doc);

               

                oFile.Writeln(pgf.Name);

                       

                        pgf = pgf.NextPgfInFlow;

                    }

                   

                oFile.close();

            • 3. Re: Output function (results to a file) in Extendscript
              klk_nc Level 1

              OK, was in a hurry, see that the new is a resreved word, this should be closer, there are no errors but no text output, I'll keep trying...

               

              //Process the paragraphs and tables in the main document flow

               

                      var textList, count = 0, i = 0, tbl = 0, pgf = 0;

                      var tagsFile = new File ("C:\extend\tag_list.txt")

               

                      // Turn off the document display to speed the script and

                      // prevent screen flicker.

                      if (app.Displaying == 1) {

                      app.Displaying = 0;

                      }

                     

                      //Process each top-level paragraph in document

                     

                      tagsFile.open("a");

                      pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

               

                      while (pgf.ObjectValid()) {

                     

                  //!!    applyNewPgfFmt(pgf,doc);

                 

                          tagsFile.writeln (pgf.NextPgfInFlow);

                         

                          // pgf = pgf.NextPgfInFlow;

                      }

                     

                  tagsFile.close();

              • 4. Re: Output function (results to a file) in Extendscript
                4everJang Level 3

                Keith,

                 

                There are a couple of problems with your script.

                1. You need to 'escape' the backslash in strings. So the code for creating your file should look like this:

                 

                var tagsFile = new File ("C:\\extend\tag_list.txt")

                 

                2. You cannot write the pgf to a text file as the pgf is an object that contains a whole lot of properties. I am not sure which property you want to write to the text file, but if you want to write the paragraph format tag, you should use:

                 

                tagsFile.writeln (pgf.NextPgfInFlow.Name);

                 

                Good luck

                 

                Jang

                • 5. Re: Output function (results to a file) in Extendscript
                  klk_nc Level 1

                  Thanks, I got it to work, with using foraward slashes and an extra step, is there an advantage to your code? Sometimes mine will lock up Frame:

                   

                  function processDoc (doc) {

                   

                          //Process the paragraphs and tables in the main document flow

                   

                          var textList, count = 0, i = 0, tbl = 0, pgf = 0;

                          var tagsFile = new File ("/<path>/For_Keith/tag_list.txt")

                          alert (tagsFile);

                   

                          // Turn off the document display to speed the script and

                          // prevent screen flicker.

                          if (app.Displaying == 1) {

                          app.Displaying = 0;

                          }

                         

                          //Process each top-level paragraph in document

                         

                          tagsFile.open("w");

                          pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

                   

                          while (pgf.ObjectValid()) {

                         

                      //!!    applyNewPgfFmt(pgf,doc);

                     

                              tagsFile.writeln (pgf.Name);

                             

                              pgf = pgf.NextPgfInFlow;

                               

                          }

                   

                     

                       tagsFile.close();  

                      

                     }

                  • 6. Re: Output function (results to a file) in Extendscript
                    4everJang Level 3

                    Hi Keith,

                     

                    I can't tell why Frame sometimes locks up, as I don't know what your applyNewPgfFmt function looks like. I would keep displaying on until the code is perfected and well-tested, then use the debug mode to step through until it hits the spot where Frame locks up. You can also write debug messages to either a text file or the console, simply by using the function Console( "message" );

                     

                    Good luck

                     

                    Jang