8 Replies Latest reply on Oct 28, 2009 7:13 PM by Roy Marshall

    [JS][CS3] Zoom frame to window

    Roy Marshall Level 1

      Hi All.

       

      I need to iterate through image/text frames while doing other formatting stuff, but I want the selected frame to fit to screen.

      I have found bits on other threads:

       

      myFrame1.select();

      myDoc1.layoutWindows[0].zoomPercentage = 200;

       

      will enlarge the selected frame to 200, but not centred on the screen.

       

      I have looked through the JS Library, and found a zoom options method, and trying to use this:

       

      myDoc1.layoutWindows[0].ZoomOptions = 2053534832;

       

      doesn't work.

       

      Can someone offer any help with this?

       

      Cheers

       

      Roy

       

        • 1. Re: [JS][CS3] Zoom frame to window
          Roy Marshall Level 1

          I am using this to compare 2 documents.

           

          A strange thing I have noted, when using the code below:

           

          myFrame1.select();

          myDoc1.layoutWindows[0].zoomPercentage = 400;

          myFrame2.select();

          myDoc2.layoutWindows[0].zoomPercentage = 400;

           

          where myDoc1 is the selected doc, and myDoc2 is the background doc, myDoc1 seems to zoom ok to the selection, but myDoc2 does not.  It does zoom, but doesn't centre the selection.

          • 2. Re: [JS][CS3] Zoom frame to window
            Kasyan Servetsky Level 5

            I am using this to compare 2 documents.

             

             

            I've written a script that does it. — http://kasyan.ho.com.ua/compare_two_documents.html

            Warning! It's not totally tested yet.

             

             

            Kasyan

             

            P.S. See also 'Zoom in on Object' article on Dave Saunder's blog http://jsid.blogspot.com/2006_01_01_archive.html

            • 3. Re: [JS][CS3] Zoom frame to window
              Roy Marshall Level 1

              Hi Kasyan & all

               

              Thanks for the heads up on your script.  Its cool, but serves a different need to mine.  I actually saw Daves script before, but was not able to help me in my quest.

               

              I nearly have the windows doing what I want, but cannot get both windows to zoom in on the selected item.  The script I have included here will zoom both windows to 200%, and to the same part of the screen for each, which is not what I want.

              I also want to use the fit.page method instead of 200% but couldn't get it working.

               

              app.documents[0].select(myFrame1);//myFrame1 is already defined and is fine

              app.documents[0].layoutWindows[0].zoomPercentage = 200;

              app.documents[1].select(myFrame2);//myFrame2 is already defined and is fine

              myWindow = app.activeWindow;

              app.documents[1].layoutWindows[0].zoomPercentage = 200;

              app.documents[0].select(myFrame1);

               

              My head hurts now, and need a drink!

               

              Any pointers will be fondly received.

               

              Roy

              • 4. Re: [JS][CS3] Zoom frame to window
                Kasyan Servetsky Level 5

                Roy,


                Try this — I assume that myFrame1 and 2 are on pages and not nested into groups, etc:

                 

                myFrame1 = app.documents[0].rectangles[0];
                myFrame2 = app.documents[1].rectangles[0];

                 

                app.documents[0].select(myFrame1);
                myWindow = app.documents[0].layoutWindows[0];
                myWindow.activePage = myFrame1.parent;
                myWindow.zoom(ZoomOptions.FIT_PAGE);

                 

                app.documents[1].select(myFrame2);
                myWindow = app.documents[1].layoutWindows[0];
                myWindow.activePage = myFrame2.parent;
                myWindow.zoom(ZoomOptions.FIT_PAGE);

                 

                Kasyan

                1 person found this helpful
                • 5. Re: [JS][CS3] Zoom frame to window
                  Roy Marshall Level 1

                  Hi Kasyan

                   

                  Thanks for that, although my frame is part of a group so I have aded another '.parent' as below:

                  myWindow.activePage = myFrame1.parent.parent

                   

                  but, both pages are zooming to the whole page, not the selection.

                   

                  myWindow.activePage = myFrame1.parent.parent;  --is getting the entire page

                  myWindow.zoom(ZoomOptions.FIT_PAGE);  --is making the entire page fit, not the selection

                   

                  I will look at this and try to mod it to work a bit later.

                   

                  Thanks for the help, it is appreciated.

                   

                  Cheers

                   

                  Roy

                  • 6. Re: [JS][CS3] Zoom frame to window
                    [Jongware] Most Valuable Participant

                    After the bit that zooms to page, you have to do Dave's (sweet!) trick to get the pixel-to-page ratio, so it can calculate the exact zoom percentage you need.

                     

                    I think you can just copy his function zoomObject(theObj) code at the end of your script, then use

                     

                    zoomObject (myFrame1.parent.parent); // See [Edit]

                     

                    instead of setting your own zoom options.

                     

                    [Edit] Well, don't if "myWindow.activePage = myFrame1.parent.parent" does return a page. Debug using

                     

                    alert (myFrame1.parent.parent.constructor.name);

                     

                    -- it should shay "TextFrame", or perhaps "Group", but not "Page" or "Spread". Cut off ".parent"'s until it works; it might even work with plain

                     

                    zoomObject (myFrame1);

                    • 7. Re: [JS][CS3] Zoom frame to window
                      [Jongware] Most Valuable Participant

                      (Afterthought) It might be your first script failed because the app.documents array is not fixed; rather, it gets updated whenever you change the activeDocument. app.documents[0] will always point to the active window, and app.documents[1] to the other document. If you change the active document during the script, these values will also swap.

                      • 8. Re: [JS][CS3] Zoom frame to window
                        Roy Marshall Level 1

                        Hey, about the app.documents[0]......  I did think about that, and wondered if that may be an issue, but dismissed it!

                         

                        I will let you know of my progress using your earlier post.

                         

                        Cheers

                         

                        Roy