4 Replies Latest reply on Mar 10, 2015 2:21 AM by Vincent-Sweden

    Command in Java for "all opened documents"

    Vincent-Sweden Level 1

      I have a script that needs modification. Thank you all in the forum for helping me design this script from start btw!

       

      Anyway, this is the script.

       

      var myDoc = app.activeDocument;

      app.findGrepPreferences = app.changeGrepPreferences = null;

      // Change "Condition 1" to name of your condition

      myConditionList = app.activeDocument.conditions.everyItem().getElements();

       

      for (i=myConditionList.length-1; i>=0; i--)

      {

          if (myConditionList[i].visible == false)

          {

              myConditionList[i].visible = true;

              app.findGrepPreferences.appliedConditions = [myConditionList[i].name] ;

              app.findGrepPreferences.findWhat = ".+";

              myDoc.changeGrep();

              app.activeDocument.conditions.item(myConditionList[i].name).remove();

          }

      }

       

      I'm looking for a variable that can apply for "all" opened documents rather than the active one only. I'm having difficulty finding the right command.

       

      BTW, the script removes all hidden text and objects.

        • 1. Re: Command in Java for "all opened documents"
          Peter Spier Most Valuable Participant (Moderator)

          I've moved your question to the scripting forum....

          • 2. Re: Command in Java for "all opened documents"
            Jump_Over Level 5

            Hi,

             

            You can call changeGrep() with various targets, i.e. with app.documents.everyItem()

             

            var
              mTarget = app.documents.everyItem(), //
              myConditionList = mTarget.conditions.everyItem().getElements();
            
            app.findGrepPreferences = app.changeGrepPreferences = null;
            
            
            for (var i=myConditionList.length-1; i>=0; i--)
                if (myConditionList[i].visible == false)
                {
                    myConditionList[i].visible = true;
                    app.findGrepPreferences.appliedConditions = [myConditionList[i].name] ;
                    mTarget.changeGrep();
                    myConditionList[i].remove();
              }
            

             

            Jarek

            • 3. Re: Command in Java for "all opened documents"
              Laubender Adobe Community Professional & MVP

              @Vincent – all opened InDesign documents, saved or not, are:

               

              app.documents
              

               

              You will get an array of all opened documents that you can loop through by:

               

              var allOpenedDocsArray = app.documents.everyItem().getElements();
              

               

               

              Uwe

              • 4. Re: Command in Java for "all opened documents"
                Vincent-Sweden Level 1

                Programming has never been my strong side. Never understood it properly and probably never will =(. But thank you solving it. The code "JUMO_OVER" wrote, worked like charm. No need to execute the script 10x for 10 documents.

                 

                Pardon me for giving you guys more out headaches, I have two additional scripts that needs revision for the same purpose as above, i.e. able to exceute the scrip for all opened docs, saved or unsaved. I would really appreciated if you guys could help me convert them. I tried it do it on my own own, but I can't get it working... =(

                 

                Delete Empty Frames in active doc

                 

                var myStories = app.activeDocument.stories.everyItem().getElements();

                for (i = myStories.length - 1; i >= 0; i--)

                {

                    var myTextFrames = myStories[i].textContainers;

                    for (j = myTextFrames.length - 1; j >= 0; j--)

                    {

                        if (myTextFrames[j].contents == "")

                  {

                            myTextFrames[j].remove();

                        }

                    }

                }

                 

                Delete Empty Pages in active doc

                 

                app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT,"Remove  Blank Pages");

                 

                function main () {

                    if (app.documents.length === 0) {

                        alert ("Please open a document.");

                        return;

                    }

                    app.scriptPreferences.enableRedraw = false;

                    removeBlankPages (app.Documents);

                    app.scriptPreferences.enableRedraw = true;

                    function removeBlankPages (doc) {

                        var pages = doc.pages.everyItem().getElements().slice(0);

                        var i = pages.length;

                        while (i-- >1) { // a bit quicker here

                            !pages[i].allPageItems.length && pages[i].remove ();

                            }

                        !pages[i].allPageItems.length && pages[i] != doc.pages[-1] && pages[i].remove ()

                    }

                }

                 

                 

                 

                BTW, I didn't write them. So they may look quirky in your eyes.