Skip to main content
Participant
February 10, 2010
Question

Zoom To Selection

  • February 10, 2010
  • 1 reply
  • 1095 views

Can anyone help me with a zoom to selection script?

It is pretty easy to get the selection bounds:

var bounds:UnitRect;
     bounds = Photoshop.app.activeDocument.selection.bounds;

But how can I use this with the zoom tool, nothing is recorded in the ScriptingListener when using the zoom tool so can't even hack that code?

Kevin

This topic has been closed for replies.

1 reply

Inspiring
February 10, 2010

If I understand what you want to do, I don't think you can do it with a script. You can set the zoom with the function below. So you could have the script work out what zoom would be needed to get the current selection to the screen size. What you can't do with a script is control the position of the image on the screen.

For example if you had the image at Actual Pixels and made a selection near the top left of the image when you zoom the window is centered on the image so the selected region will be off screen if the zoom is large enough.

And as you pointed out, zoom dragging is not recorded.

function setZoom( zoom ) {// as percent
   cTID = function(s) { return app.charIDToTypeID(s); }; // from xbytor
   var docRes = activeDocument.resolution;
   activeDocument.resizeImage( undefined, undefined, 72/(zoom/100), ResampleMethod.NONE );
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
   ref.putEnumerated( cTID( "Mn  " ), cTID( "MnIt" ), cTID( 'PrnS' ) );
   desc.putReference( cTID( "null" ), ref );
   executeAction( cTID( "slct" ), desc, DialogModes.NO );
   activeDocument.resizeImage( undefined, undefined, docRes, ResampleMethod.NONE );
}
setZoom( 65 );