Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- zoom(activeDocument.selection[0]);
- function zoom(object) {
- var doc = app.activeDocument;
- if (doc !== undefined) {
- var view = doc.views[0];
- var viewBounds = view.bounds;
- var viewDimentions = dimentions(viewBounds);
- var objectBounds = object.geometricBounds;
- var objectDimentions = dimentions(objectBounds);
- var orientation = objectDimentions.width >= objectDimentions.height ? "landscape" : "portrait";
- var currentZoom = view.zoom;
- var visibleWidth = viewDimentions.width * currentZoom;
- var visibleHeight = viewDimentions.height * currentZoom;
- var margin = 56.692913385826772;
- var zoom = orientation === "landscape" ? (visibleWidth / (objectDimentions.width + margin)) : (visibleHeight / (objectDimentions.height + margin));
- var x = (objectBounds[0] + objectBounds[2]) / 2;
- var y = (objectBounds[1] + objectBounds[3]) / 2;
- view.centerPoint = [x, y];
- view.zoom = zoom;
- }
- }
- function dimentions(bounds) {
- return {
- width : bounds[2]-bounds[0],
- height : bounds[1]-bounds[3]
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement