Advertisement
OSRSMargins

Untitled

Nov 1st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. zoom(activeDocument.selection[0]);
  2.  
  3. function zoom(object) {
  4.     var doc = app.activeDocument;
  5.     if (doc !== undefined) {
  6.         var view = doc.views[0];
  7.         var viewBounds = view.bounds;
  8.         var viewDimentions = dimentions(viewBounds);
  9.  
  10.         var objectBounds = object.geometricBounds;
  11.         var objectDimentions = dimentions(objectBounds);
  12.  
  13.         var orientation = objectDimentions.width >= objectDimentions.height ? "landscape" : "portrait";
  14.  
  15.         var currentZoom = view.zoom;
  16.         var visibleWidth = viewDimentions.width * currentZoom;
  17.         var visibleHeight = viewDimentions.height * currentZoom;
  18.         var margin = 56.692913385826772;
  19.         var zoom = orientation === "landscape" ? (visibleWidth / (objectDimentions.width + margin)) : (visibleHeight / (objectDimentions.height + margin));
  20.  
  21.         var x = (objectBounds[0] + objectBounds[2]) / 2;
  22.         var y = (objectBounds[1] + objectBounds[3]) / 2;
  23.  
  24.         view.centerPoint = [x, y];
  25.         view.zoom = zoom;
  26.  
  27.     }
  28. }
  29.  
  30. function dimentions(bounds) {
  31.     return {
  32.         width : bounds[2]-bounds[0],
  33.         height : bounds[1]-bounds[3]
  34.     };
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement