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

Get the current zoom of the document.

Engaged ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hello people!
How to get the current zoom of the document.
I'm trying to add two buttons to control the zoom value, but I need the initial value.
So far I have this, I still need to get the initial value

#target photoshop;  
z=100; // the initial value is missing
dlg = new Window("dialog"); dlg.text = "Dialog"; 
b1 = dlg.add("button", undefined, undefined, {name: "b1"}); b1.text = "+"; 
b2 = dlg.add("button", undefined, undefined, {name: "b2"}); b2.text = "-"; 

checkbox1 = dlg.add("checkbox", undefined, undefined, {name: "checkbox1"}); 
checkbox1.text = "Checkbox"; 

b1.onClick = function() {z= z+15; zoomDocs(z);}; 
b2.onClick = function() {z= z -15; zoomDocs(z);};

dlg.show();

function zoomDocs(z){
if(documents.length){  
var startRulerUnits = preferences.rulerUnits;  
app.preferences.rulerUnits = Units.INCHES;  
var Width = app.activeDocument.width;  
 setZoom (z);  
preferences.rulerUnits = startRulerUnits;  
};      
function setZoom( zoom ) {    
    if(zoom < 1 ) zoom =1;    
    var ref = new ActionReference();    
    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );    
    var getScrRes = executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;    
    var docRes = activeDocument.resolution;    
    activeDocument.resizeImage( undefined, undefined, getScrRes/(zoom/100), ResampleMethod.NONE );    
    var desc = new ActionDescriptor();    
    ref = null;    
    ref = new ActionReference();    
    ref.putEnumerated( charIDToTypeID( "Mn  " ), charIDToTypeID( "MnIt" ), charIDToTypeID( 'PrnS' ) );    
    desc.putReference( charIDToTypeID( "null" ), ref );    
    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );    
    activeDocument.resizeImage( undefined, undefined, docRes, ResampleMethod.NONE );    
   }; 
}
TOPICS
Actions and scripting

Views

384

Translate

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 , Nov 25, 2020 Nov 25, 2020

Seems I forgot a (sub-)function: 

var aaa = getZoom();
alert (aaa);
/* 
* Retrieve the Zoom % 
*  {Number} Zoom value (%) 
*/  
function getZoom () {  
  var ref;  
  ref = new ActionReference();  
  ref.putProperty(s2t("property"), s2t("zoom"));  
  ref.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"));  
  return executeActionGet(ref).getUnitDoubleValue(s2t("zoom")) * 100;  
};
function s2t (s) {  
    return app.stringIDToTypeID(s);  
  }; 

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

I think @DBarranca provided this a while ago: 

 

/* 
* Retrieve the Zoom % 
*  {Number} Zoom value (%) 
*/  
getZoom = function() {  
  var ref;  
  ref = new ActionReference();  
  ref.putProperty(s2t("property"), s2t("zoom"));  
  ref.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"));  
  return executeActionGet(ref).getUnitDoubleValue(s2t("zoom")) * 100;  
};  

 

Votes

Translate

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 ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Can you get the zoom value with this script?

Capturar.PNG

Votes

Translate

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 ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Seems I forgot a (sub-)function: 

var aaa = getZoom();
alert (aaa);
/* 
* Retrieve the Zoom % 
*  {Number} Zoom value (%) 
*/  
function getZoom () {  
  var ref;  
  ref = new ActionReference();  
  ref.putProperty(s2t("property"), s2t("zoom"));  
  ref.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"));  
  return executeActionGet(ref).getUnitDoubleValue(s2t("zoom")) * 100;  
};
function s2t (s) {  
    return app.stringIDToTypeID(s);  
  }; 

Votes

Translate

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 ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

Great support, now it worked well! I had tested the first script and nothing was happening. Thanks c.pfaffenbichler .

Votes

Translate

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 ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

LATEST

You’re welcome. 

As I mentioned I had forgotten stuff in the first post. 

Votes

Translate

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