Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Working with multiple documents-javascript

Return to Member Forum

  • Author
    Posts
    • #63157

      Hello,

      I have written a script that will cycle through some open indesign files (or a single file) and apply a bunch of specific layout corrections. These are enabled/disabled on a dialog window. One of the options is to either save and close each file as it is corrected or to leave them all open after the script has finished. When I run it on and choose to not save, everything works exactly as intended. The problem is with the save/close option. When this is selected the script stops after processing roughly half of the files. It doesn't report any errors, it just stops. Can anyone shed any light on to why this is happening.

      Here is the section of the script where the save occurs. If it would help to post the rest I can do. Rad1 is the radio button to select between all open documents or the active one and rad4 is the save/don't save button.

      function artworkFixes(){

      if(g.rad1.value == true){

      for(var i = 0; i < app.documents.length; i++){

      g.myDoc = app.documents[i];

      g.pageWidth = g.myDoc.documentPreferences.pageWidth;

      bleedFix();

      slugFix();

      varFix();

      layerFix();

      swatchFix();

      cutterFix();

      if(g.rad4.value == true){

      g.myDoc.close(SaveOptions.YES)

      }

      }

      }

      Any help would be greatly appreciated!

    • #63162

      You are using the applications document list, but as soon as you close one of your documents this list is re-built in memory, and the “current one”, the one you are looking at, is invalidated.

      You can work around a couple of ways; one of them would be to create an array of your own, where you maintain a list of “documents to process”. Remove it from the list after processing (whether you saved and closed it or not). When the list is empty, you are done.

    • #63165

      Thanks for the tip. I have that working now.

      One last thing though. Could you let me know how I can check to see if a particular layer (by name) exists and if it does then stop the script with an alert. When this layer name occurs on a document I need to be aware of it as I need to manually adjust the content.

      Thanks again!

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads