A little change is required in the script, please help.

I am using a script named as <Zoom to Width> that I found on web. This script does two jobs
(1) zoom to a specific percentage
(2) and center the page horizontally as well vertically at that zoom level.
I have changed the zoom value to 170% in it. Now the problem is that when script center the page at 170% it shows the middle of the page (horizontal as well as vertical). I need horizontal center but not vertical center of page, so I have to move to the top of page by scrolling or by moving cursor. I want a little change in it that vertically top of the page should appear instead of the middle of page i.e.
I want 170% zoom + horizontal page center + vertical page top.
I would appreciate any help. I am on Windows 64bit. Here is the script
//DESCRIPTION: Zooms to the width of currently selected object or the current page. http://www.in-tools.com
ZoomToWidth();
function ZoomToWidth(){
    var kAppVersion=parseFloat(app.version);
    try{
        if(File.fs == "Macintosh"){var isMac = true}
        else{var isMac = false}
        if(kAppVersion>=6 && app.generalPreferences.useApplicationFrame){
            var usesApplicationFrame = true;
        else{var usesApplicationFrame = false}
        var sel=app.selection[0];
        var window = app.activeWindow;
        if(! (window instanceof LayoutWindow) ){return}
        var doc = app.documents[0];
        var horizViewPrefs = doc.viewPreferences.horizontalMeasurementUnits;
        doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
        var theWidth = doc.documentPreferences.pageWidth;
        var theHeight = doc.documentPreferences.pageHeight;
        var theSpread = window.activeSpread;
        var pagesLength = theSpread.pages.length;
        if(isMac){
            var windowWidth = window.bounds[3]-window.bounds[1]-35;
            if(usesApplicationFrame){
                window.zoom(ZoomOptions.fitSpread);
                var spreadZoom = window.zoomPercentage;
                windowWidth = (spreadZoom/170)*(theWidth*pagesLength);
        else{
            var windowWidth = window.bounds[3]-window.bounds[1]-50;
            if(usesApplicationFrame){//|| pagesLength>1 || theWidth>theHeight
                window.zoom(ZoomOptions.fitSpread);
                var spreadZoom = window.zoomPercentage;
                windowWidth = (spreadZoom/170)*(theWidth*pagesLength);
        if(sel && (sel.hasOwnProperty("parentTextFrames") || sel.hasOwnProperty("visibleBounds")) ){
            if(sel.hasOwnProperty("parentTextFrames")){
                var textFrame = sel.parentTextFrames[0];
                var frameBounds = textFrame.visibleBounds;
                app.select(sel.parentTextFrames[0]);
            else{frameBounds = sel.visibleBounds}
            theWidth = frameBounds[3]-frameBounds[1];
        else{window.zoom(ZoomOptions.fitPage)}
        window.zoomPercentage = (windowWidth/theWidth)*170;
        doc.viewPreferences.horizontalMeasurementUnits = horizViewPrefs;
        app.select(sel);
    catch(e){}

Hi,
Basically your function is zooming base to width (selected object or window) so instead of modifying I suggest to create a new a "base to scale" function.
To keep top window content shown after scaling one can use a trick and select temporalily created object in a center (remove it after), so:
function zoomToScale(myScale) {
  if (isNaN(myScale) || myScale > 4000 || myScale < 4) myScale = 100;
  var
  window = app.activeWindow,
  mDoc = app.activeDocument,
  mZeroPoint = mDoc.zeroPoint,
  mHorizViewPrefs = mDoc.viewPreferences.horizontalMeasurementUnits,
  mActiveSpread = window.activeSpread,
  mSpreadPages = mActiveSpread.pages.length,
  mWidth, theRec, mTopCenter;
  mDoc.zeroPoint = [0,0];
  mDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
  mWidth = mDoc.documentPreferences.pageWidth;
  theRec = mActiveSpread.rectangles.add();
  mTopCenter = mWidth*mSpreadPages / 2;
  theRec.move(undefined,[mTopCenter,0]);
  window.zoom(ZoomOptions.fitSpread);
  window.zoomPercentage = myScale;
  app.selection = theRec;
  theRec.remove(); 
  mDoc.zeroPoint = mZeroPoint;
  mDoc.viewPreferences.horizontalMeasurementUnits = mHorizViewPrefs;
call it i.e. this way:
zoomToScale(170);
myScale is reset to 100 if it is out of range or is not a number
Jarek

Similar Messages

Maybe you are looking for

  • ITunes 10.6.3 memory leak

    Anyone else having issues with iTunes 10.6.3 running on OSX 10.7.4 leaking memory dry and then filling up ALL your disk partition?  I do - once a week now. I have a small boot SSD, but once iTunes fills up the memory it appears to be creating a 30+ G

  • Exit for changing Components in ME21N based on the production Order

    Hi,       I have a scenerio in which, while creating PO in ME21N for subcontracting(Item category 'L') against a PR, the components for the material should come with my own logic i.e. it will have its production order number, with this production num

  • Ipod screen on while connected to mac

    Screen stays on when connected to my mac, seems to prevent it from getting a full charge. If I eject ipod and leave connected, the screen dims, then it will charge. Is this normal? I wish the screen would dim, I use it as a external disk too.

  • Any tips for creating a realistic midi cymbal swell?

    surely there has be to a way to create a nice cymbal swell - I used to use cubase but it never sounded realistic just filling in a large number of cymbal crashes jammed together - too percussive. any assistance would be awesome! thanks, stefano targh

  • Main Stage & 3rd party plug ins

    I'm a Main Stage newbie with 3rd party plugins (Ivory II; Kontakt 5) I would like to use via Main Stage. Having difficulty. After clicking and holding I/O, I do find "AU Instruments" in the dropdown menu with the plug-ins I've installed, but how do I