9 Replies Latest reply on Nov 12, 2013 7:02 AM by myDavey

    Zoom settings change when adding pages

    myDavey Level 1

      Hi

      When adding a page to a document with this code:

      app.activeDocument.pages.add(LocationOptions.AT_END);
      

      InDesign automatically reverts the zoom setting to FIT_TO_PAGE

       

      Is there a way to prevent this from happening?

      I would like that it should stay at whatever it was.

       

       

      Help will be much appreciated!

       

      Thanks,

      Davey

        • 1. Re: Zoom settings change when adding pages
          csm_phil Level 4

          Hi Davey_Doo,

           

          Please try the below JS code its working in CS5.5.

           

           

          var myPreZoomSet = (app.activeDocument.windows[0].zoomPercentage);
          app.activeDocument.pages.add(LocationOptions.AT_END);
          app.activeDocument.windows[0].zoomPercentage = myPreZoomSet;
          

           

          thx,

          csm_phil

          • 2. Re: Zoom settings change when adding pages
            myDavey Level 1

            Hi csm_phil

            Thanks for your response!

            I happen to have just discovered that!

            I wrote this code:

            currentZoom = theDoc.layoutWindows[0].zoomPercentage;
            theDoc.pages.add(LocationOptions.AT_END);
            theDoc.layoutWindows[0].zoomPercentage = currentZoom;
            

             

            I have 2 questions now:

            1) is there a difference between what I wrote "layoutWindows[0]" and what you wrote "windows[0]"?

             

            2) Although this does help, is there a way to prevent it from happening?

                 The reason I ask is because in a script which adds many pages, (e.g., MultiPageImporter script), the script needs to do this after adding each page.

                 If there would be a lock setting or something like that, it would be much more sufficient.

             

             

            Thanks again!

            Davey

            • 3. Re: Zoom settings change when adding pages
              [Jongware] Most Valuable Participant

              Davey_Doo wrote:

               

              1) is there a difference between what I wrote "layoutWindows[0]" and what you wrote "windows[0]"?

               

              Yup, "layoutWindows" refer to just the layout windows -- the ones one is normally working in. The other kind is "storyWindows", which is what you get when you open a text in the "Story Editor". There are vast differences between the two, such as "zoom" (you cannot zoom in on the story editor window).

               

              Using "windows", without specifying the kind, you get a list containing both types; and using "windows[0]", you get the very first one, whether it is a story window or a layout window. Then, if it happens to be a story window, csm_phil's script will Crash & Burn because you cannot zoom in on a story window.

               

              Your version will work correctly, and just in case you might have a story editor window open, it's best to stick to "layoutWindows" if you want to change a layout window property.

               

               

              2) Although this does help, is there a way to prevent it from happening?

                   The reason I ask is because in a script which adds many pages, (e.g., MultiPageImporter script), the script needs to do this after adding each page.

               

              No, you cannot prevent it in any way. It's just ID's default built-in behavior (although it seems strange that this only happens when using a script!).

              But I disagree with your assessment it needs to be done "after adding each page". ID does not store the zoom percentage for each separate page and so it is enough to read the current zoom, add as much pages as you like, then set the zoom.

              • 4. Re: Zoom settings change when adding pages
                Jump_Over Level 5

                Hi,

                 

                You could consider opening your doc with no window applied to avoid display calls, i.e.:

                 

                myDoc = app.open(mFile,false);
                

                 

                So let your script do tasks in "hidden mode" and finally add window with activePage and zoomPercentage properties set as you like.

                 

                myDoc.windows.add();
                with (myDoc.layout Windows[0]) {
                     activePage = myDoc.pages[0];     // stored page?
                     zoomPercentage  = myPreZoomSet     // stored zoom;
                     }
                

                 

                Jarek

                • 5. Re: Zoom settings change when adding pages
                  myDavey Level 1

                  Hi guys, thanks a lot!!

                  (Sorry for not responding sooner, I was out yesterday)

                   

                  @Jongware

                  Regarding the layoutWindows VS windows,

                       thanks a lot for the clear explanation that provided Important information!

                   

                  Regarding the 'adding after each page'

                       I also had your idea, however, I am working with an existing script written by Scot Zanelli

                       In the script (which is very long and detailed) he adds one page at a time when necessary

                       So what i emant was that since the script adds pages one by one, I will need it to adjust the zoom each time around

                   

                   

                  @Jump_Over

                  Thats a nice idea!

                  But is it possible to hide a document which is already open?

                   

                   

                  Thanks again!

                  Davey

                  • 6. Re: Zoom settings change when adding pages
                    Jump_Over Level 5

                    Davey_Doo wrote:

                     

                    ...

                    But is it possible to hide a document which is already open?

                     

                     

                    Hi,

                     

                    Is not so straight but you could use this:

                     

                    app.activeDocument.layoutWindows[0].minimize();
                    
                    // ... do some job ...
                    
                    if (app.generalPreferences.useApplicationFrame) app.fullName.execute();
                    else app.activeDocument.layoutWindows[0].restore();
                    

                     

                    Jarek

                    • 7. Re: Zoom settings change when adding pages
                      myDavey Level 1

                      Hi Jarek

                      Thanks so much

                      I will try it soon

                       

                      But can you please explain to me what the second to last line is for?

                       

                      if (app.generalPreferences.useApplicationFrame) app.fullName.execute();
                      

                       

                       

                      Thanks again

                      Davey

                      • 8. Re: Zoom settings change when adding pages
                        Jump_Over Level 5

                        Hi,

                         

                        Your doc window can be docked in app window or not.

                        If yes ==> doc.windows[0].restore() doesn't work.

                         

                        Jarek

                        • 9. Re: Zoom settings change when adding pages
                          myDavey Level 1

                          Got it!

                          Thanks a lot!

                           

                          Davey