Highlighted

can I save contents of Javascript Console and clear it from script?

Explorer ,
Jun 15, 2020

Copy link to clipboard

Copied

I am running Extendscript and writing messages to Javascript Console.  At some point, it clears itself and goes on, losing all the past messages.

The question is, can I detect that the console is about full, save the contents of the cosole, clear it, and then go on?

Short of that, I just limit the run through certain counter and just stop it before going on, and manually change parameters and continue.  Since I am creating 6000 some flash cards in separate PDF files, this is not very desirable.

I have searched the documentation and the Net, and could not find anything.  Can I be the only one running into this problem?

I am runnin Illustrator 2020, installed in April.

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

An alternative, why not write the messages in a log file instead of console. You could create a small library that could be switched from console to a log file as needed.

 

-Manan

Topics

Scripting, Tools

Views

185

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

can I save contents of Javascript Console and clear it from script?

Explorer ,
Jun 15, 2020

Copy link to clipboard

Copied

I am running Extendscript and writing messages to Javascript Console.  At some point, it clears itself and goes on, losing all the past messages.

The question is, can I detect that the console is about full, save the contents of the cosole, clear it, and then go on?

Short of that, I just limit the run through certain counter and just stop it before going on, and manually change parameters and continue.  Since I am creating 6000 some flash cards in separate PDF files, this is not very desirable.

I have searched the documentation and the Net, and could not find anything.  Can I be the only one running into this problem?

I am runnin Illustrator 2020, installed in April.

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

An alternative, why not write the messages in a log file instead of console. You could create a small library that could be switched from console to a log file as needed.

 

-Manan

Topics

Scripting, Tools

Views

186

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 15, 2020 0
Adobe Community Professional ,
Jun 15, 2020

Copy link to clipboard

Copied

An alternative, why not write the messages in a log file instead of console. You could create a small library that could be switched from console to a log file as needed.

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 15, 2020 0
Explorer ,
Jun 17, 2020

Copy link to clipboard

Copied

Thanks!  It sounds good.  I did not think of it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2020 0
Adobe Community Professional ,
Jun 15, 2020

Copy link to clipboard

Copied

Why do you need to write 6000 lines of text to the console? What do you do with that information?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 15, 2020 0
Explorer ,
Jun 17, 2020

Copy link to clipboard

Copied

I am creating 6000+ flash cards in 9 colors, with a template for each color.  For each template, I use VariableImport to obtain data from my .csv file, vectorize and then save as .pdf.  (file name is also stored in the .csv file). I put a line or two to the log to confirm that each card is saved.  Also, for each card, I put out information about adjustments I made to texts that are too wide for the text box, as Illustrator does not auto-adjust text size to fit the box, as Excel can do.

The log is important for me to verify that everything is fine before I send them out to the printer.

 

Currently, I am babysitting the execution and periodically cut out the log content and save it somewhere else.  Not very desirable.

 

By the way, hoping that I can see progress from AI window, I also put $.sleep() statements after save and after update dataset operation.  The window does update for a few cards and then stays unchanged for the rest of the execution.  This is also not like Excel VBA execution.  But this is more of a curiosity so I choose to live with it.

 

As a novice, I find Illustrator scripting quite finicky and not completely reliable.  The biggest annoyment is that it hangs after about 200 some cards, and I have to kill it and restart from the last card.  Once in a while (about one or two in 700 or so), a .pdf file of zero size would be generated.  But, I am thankful that Illustrator has enough functionality to allow me to muddle throuth.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2020 0
Adobe Community Professional ,
Jun 17, 2020

Copy link to clipboard

Copied

oh ok, you use the console as a log data to verify the status of each record.

 

as Manan mentioned, a log file is the way to go. The console does have a limit of how much data it can hold (I haven't investigated what the limit is).

 

As for the progress window, it is tricky but it should update even if Illustrator seems frozen processing that many records.

 

Are you using an actual Progress bar object from Script UI? post a snipet of your code, we migh be able to help you getting it to update.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2020 0
Explorer ,
Jun 17, 2020

Copy link to clipboard

Copied

No, I am not using the Progress bar.  I saw ScriptUI in the manual, but did not pay attention to it as I thought that I am not interacting with the user.

 

Thank you for pointing this out.  It sounds more approapriate.  I am currently using $.writeln() as my progress report also -- in addition to files listed in Explorer (I am using Windows).

 

Here is my main program.  Hope its intent is clear.  I did not remove my comments about failed ways to do certain operations.  This Illustrator scripting is quite an experience.

 

for (var j = from; j<= to; j++) {
      baseDoc.dataSets[j].display();
      $.writeln(' j=', j, '; ', now());
      redraw();
      $.sleep(100); // in Milliseconds -- wait for screen update
      // reduce oversized texts - variables in word and grp
            var r = reduceWidthToLimit(baseDoc, 'word', 84);
            var r = reduceWidthToLimit(baseDoc, 'grp', 32);
      // vectorize all texts in the artboard
            vectorizeAllTexts(baseDoc);
      // call the function to create PDF file without changing the active document
            saveAsPDF(baseDoc, destFolder);
            $.sleep(500); // in Milliseconds -- wait for the save to complete

      // resore the original document because sometimes variables get unbound by vectorization
            closeDoc(baseDoc, 'DONOTSAVECHANGES');
            baseDoc = openDoc (baseName);
            $.sleep(400); // in Milliseconds -- wait for base doc to close and reopen

      // app.doScript ("revert", "Default Actions"); // revert document to original state
            // NOTE: not working as it opens a dialog
      // app.undo; // NOTE: not used as we do not know how many undos are needed
      }; /* end of for *

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2020 0
Adobe Community Professional ,
Jun 17, 2020

Copy link to clipboard

Copied

well you're doing extremely well, isn't it fascinating?

 

There are a few Progress Bar samples here in the forum if you make a search you'll find plenty of examples.

 

If you want to give it a try, this is what I'm using

 

place this code before your mian loop. 

pretty much we create and initialize the progress bar with the number of items you'll process

 

        // ******************************************************************************************
        var win2 = new Window("palette", "Progress Bar Title", [150, 150, 600, 260], {independent:true});   
        var pnl = win2.add("panel", [10, 10, 440, 100], "Script Progress");  
        var pb = pnl.add("progressbar", [20, 35, 410, 60], 0, 100);  
        var pbLabel = pnl.add("statictext", [20, 20, 320, 35], "0%");  
          
        win2.show();  

        // make max value equal to the items to process
        // pretty much to divide the progress bar updates in as many items as we have
        pb.maxvalue = records.length; win2.update();
        // ******************************************************************************************

 

 

 then iside your loop you need to increase the Progress Bar counter

 

// PROCESS EACH RECORD
for (a=0; a<records.length; a++) { 

  increasePBvalue (win2, pb, pbLabel); 

  DO YOUR THING
}

 

then place this function anywhere after your loop to handle to Progress Bar updating

 

function increasePBvalue (win2, pb, pbLabel) {
    // increment the bar size and display text according to the values we're processing
    ++pb.value;
    pbLabel.text = Math.round((pb.value/pb.maxvalue)*100)+"%";  
    win2.update();
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2020 0