7 Replies Latest reply on Sep 5, 2012 2:30 AM by MrTIFF

    Cycling between open documents

    willypeeters

      I am quit new to InDesign scripting.

       

      In my script I have 3 documents open and take actions in all off them.

       

      How can I make make each document alternatively active while the actions take place?

      I want the user to see what is changing.

       

      I tried

      app.activeDocument  = myDocument;

       

      where myDocument is a reference to the document. But this gives errors (undefined...).

       

      Thanks

        • 1. Re: Cycling between open documents
          MrTIFF Level 3

          I do something like this in my scripts:

           

          var win:LayoutWindow = doc.layoutWindows.item(0);

          win.activePage = doc.pages.item(0);   // set to view page 0

          win.zoom(ZoomOptions.fitPage);

          • 2. Re: Cycling between open documents
            Laubender Adobe Community Professional & MVP

            @Willy – you could identify the documents by their name property.

             

            var doc1Name = app.documents[0].name;
            var doc2Name = app.documents[1].name;
            var doc3Name = app.documents[2].name;
            

            Or you already know the names of the documents in advance…

             

            To access the documents by name, try this:

             

            var myFirstDoc = app.documents.itemByName("doc1Name");
            var mySecondDoc = app.documents.itemByName("doc2Name");
            var myThirdDoc = app.documents.itemByName("doc3Name");
            

             

            This will work until you change the names…

             

            app.activeDocument = myThirdDoc;
            

             

            Uwe

            • 3. Re: Cycling between open documents
              willypeeters Level 1

              Thanks Uwe.

              I managed to cycle with app.activeDocument but code who was working before I changed focus of documents does not work anymore after the change.

              For instance when I want to apply a paragraph style I receive a error message telling that the object is from another document or from another workspace.

              Any idea why this happens?

              • 4. Re: Cycling between open documents
                Laubender Adobe Community Professional & MVP

                I think if working with properties of a different document on another document, you first have to "bring" those properties to the document you want to work with.

                 

                An example: if you want work with paragraph style "p1" in "docA" and "p1" is not defined in "docA", but is defined in "doc B", you first have to copy some text formatted with "p1" from "docB" to "docA". Or use the import function with paragraph styles…

                 

                Uwe

                • 5. Re: Cycling between open documents
                  willypeeters Level 1

                  The right paragraph styles are in the right documents.

                  I try to explain what I would like to do with an example.

                  I have 3 doc's open : docA, docB, docC. Current active document is for example docB.

                  In my code I start building elements in succession in docA then docB and then docC.

                  When I run my code without changing focus to docA with app.activeDocument everything works fine without any error but the changes in docA and docC are not showed on screen during execution.

                  I would like that the user can follow the changes in every doc regardless of which document is active by start.

                  Using app.activeDocument to change focus to docA gives the error about another document or workspace...

                  Is there another way to accomplish what I want?

                  • 6. Re: Cycling between open documents
                    Laubender Adobe Community Professional & MVP

                    Hm. For that I have no answer. Don't know if that is even possible, because a redraw of all changes you have made to a particular document is shown AFTER fully executing and finishing the script…

                     

                    Maybe I'm wrong with that…

                     

                    Uwe

                    • 7. Re: Cycling between open documents
                      MrTIFF Level 3

                      In my experience, what actually shows up on the screen while a script is executing is hard to predict, because InDesign's redraw routines are not under direct control of a script.

                       

                      That said, I think that playing with the Layout window for each document gives you the best chance at something approximating the feedback that you want.  See my suggestions previously.

                       

                      My scripts and Extensions almost always work with multiple documents simultaneously, so I'm pretty familiar with what happens :-)

                       

                      Cheers,