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 );
};
}
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);
};
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;
};
Copy link to clipboard
Copied
Can you get the zoom value with this script?
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);
};
Copy link to clipboard
Copied
Great support, now it worked well! I had tested the first script and nothing was happening. Thanks c.pfaffenbichler .
Copy link to clipboard
Copied
You’re welcome.
As I mentioned I had forgotten stuff in the first post.