Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Pan to selection script

Engaged ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

Just want to check with fellow scripters than panning (as in using the hand tool) to move around a zoomed in large image is NOT possible with scripting? 

 

I want to zoom in on a large image and then be able to pan to a selection  - but I don't think there is anything that can help me on this one. Even the navigator doesn't highlight selections.

 

So go from :

GhoulFool_1-1738748295990.pngexpand image

 

to 

GhoulFool_2-1738748306374.pngexpand image

Using a zoomed in version of the Mona Lisa an an example

 

TOPICS
Actions and scripting

Views

180
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 05, 2025 Feb 05, 2025

The code in the linked thread should preset a dialog for numeric entry but you should be able to use other input (like the active layer’s bounds/center). 

Votes

Translate
Adobe
Community Expert ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

@Ghoul Fool 

 

So you are already viewing one area of the image, say the upper left at a given zoom level, and there is a selection elsewhere in the image that you wish to zoom to?

 

If so, this can be hacked by making a new layer with content, such as filling the selection or creating a fill layer with the selection active and then View > Fit Layer(s) on Screen:

 

app.runMenuItem(stringIDToTypeID('fitLayersOnScreen'));

 

You could then add a zoom out as required:

 

app.runMenuItem(stringIDToTypeID('zoomOut'));

 

And delete the new active layer as it has served its purpose.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

Stephen, that's simple and elegant!

...but I'm trying to avoid any zooming/changing magnification levels.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

quote

Stephen, that's simple and elegant!

...but I'm trying to avoid any zooming/changing magnification levels.


By Ghoul Fool


Hah, I'd forgotten about that discussion!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

LATEST

😄

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

The code in the linked thread should preset a dialog for numeric entry but you should be able to use other input (like the active layer’s bounds/center). 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

Oooh! Things. Just. Got. Interesting.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

So if anyone's interested in order to make my version of teh script work I just removed the UI and added a function to get the selection bounds centre:

 

// get window values;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("viewInfo"));    
r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));    
var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("viewInfo")).getObjectValue(stringIDToTypeID("activeView")).getObjectValue(stringIDToTypeID("globalBounds"));
var theLeft = bounds.getUnitDoubleValue(stringIDToTypeID("left"));
var theTop = bounds.getUnitDoubleValue(stringIDToTypeID("top"));
var theRight = bounds.getUnitDoubleValue(stringIDToTypeID("right"));
var theBottom = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));
var windowW = theRight - theLeft -16;
var windowH = theBottom - theTop - 16;

// get zoom;
var theZoom = getActiveDocumentZoom();


// set potision on selection
var sb = get_selection_bounds_centre();
if (sb != undefined)
{
    var posX = sb[0]*(-1)*theZoom/100+windowW/2;
    var posY = sb[1]*(-1)*theZoom/100+windowH/2;

    set_doc_position(posX, posY);
}




//  by r-bin;
function set_doc_position(x, y)  
{  
  try
  {  
    var r = new ActionReference();    
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("viewInfo"));    
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));    
    var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("viewInfo")).getObjectValue(stringIDToTypeID("activeView")).getObjectValue(stringIDToTypeID("globalBounds"));          
    var b = new Array();
    b[0] = bounds.getUnitDoubleValue(stringIDToTypeID("left"));          
    b[1] = bounds.getUnitDoubleValue(stringIDToTypeID("top"));  
    b[2] = bounds.getUnitDoubleValue(stringIDToTypeID("right"));  
    b[3] = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));  

    var dx = 8; // what is it?  
    var dy = 8; // what is it?  

    x = (b[2]-b[0])/2 - x - dx;  
    y = (b[3]-b[1])/2 - y - dy;  

    var d = new ActionDescriptor();    
    var r = new ActionReference();    
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("center"));    
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));    
    d.putReference(stringIDToTypeID("null"), r);    

    var d1 = new ActionDescriptor();    

    d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("distanceUnit"), x);  
    d1.putUnitDouble(stringIDToTypeID("vertical"),   stringIDToTypeID("distanceUnit"), y);  

    d.putObject(stringIDToTypeID("to"), stringIDToTypeID("center"), d1);    
    executeAction(stringIDToTypeID("set"), d, DialogModes.NO);    
  }  
  catch (eeek)
  { 
    throw(eeek); 
  }  
};

// by mike hale;
function getActiveDocumentZoom()
{
   var ref;
   ref = new ActionReference();
   ref.putProperty( charIDToTypeID( "Prpr" ),charIDToTypeID('Zm  '));
   ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
   return (executeActionGet(ref).getUnitDoubleValue (charIDToTypeID('Zm  ')))*100;
};


// function GET SELECTION BOUNDS()
// ----------------------------------------------------------------
function get_selection_bounds_centre()
{
  try
  {
    var l = parseFloat(app.activeDocument.selection.bounds[0]);
    var t = parseFloat(app.activeDocument.selection.bounds[1]);
    var r = parseFloat(app.activeDocument.selection.bounds[2]);
    var b = parseFloat(app.activeDocument.selection.bounds[3]);

    var selectionBounds = [parseInt(r -((r-l)*0.5)),parseInt(t-((t-b)*.5))]; // centre x, centre y
    return selectionBounds;
  }

  catch(eek)
  {
    return undefined;
  }
}

 

No more zooming in and out for me!! 😄

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines