Copy link to clipboard
Copied
In the process of semi-automatic processing, there is a pause in my actions, where I spot-correct some points.
The situation is that after manipulation the image may be in different places in Photoshop.
Of course in this pause you can press ctr+tab, ctr+0, but you have to do it constantly and with a very large number of photos.
In this regard, I'm looking for a script that will be analogous to ctr+0 or will make the image scale 50% (this value is good for my purposes).
It is possible in an action, but it takes 3 steps.
Here it is in a script:
/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/image-view/m-p/10650951 */
setZoom(50); // as percent
function setZoom(zoom) {
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
...
@Stephen Marsh good trick!
I decided to check if it is possible to directly set the zoom and the position of the center of the image (i.e. if it is possible to make it work in any case, even with overscroll enabled). Maybe someone will need this code:
#target photoshop
var s2t = stringIDToTypeID,
zoom = 0.5;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('resolution'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var res = executeActionGet(r).getInt
...
Copy link to clipboard
Copied
It is possible in an action, but it takes 3 steps.
Here it is in a script:
/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/image-view/m-p/10650951 */
setZoom(50); // as percent
function setZoom(zoom) {
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);
}
Copy link to clipboard
Copied
Hi @Stephen Marsh ! The script does do 50%, but it doesn't center the image the way the ctrl+0 key combination does. The picture still stays in an arbitrary place
Copy link to clipboard
Copied
Here is a scripted version of the 3 action steps that I previously mentioned:
Zoom("actualPixels");
Zoom("zoomOut");
Zoom("zoomOut");
function Zoom(menuCommand) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "menuItemClass" ), s2t( "menuItemType" ), s2t( menuCommand ));
descriptor.putReference( s2t( "null" ), reference );
executeAction(s2t( "select" ), descriptor, DialogModes.NO);
}
Copy link to clipboard
Copied
@Stephen Marsh , thank you very much, your both codes started working fine after I turned off "overscroll".
Thanks @D Fosse for that tip!
Copy link to clipboard
Copied
@Stephen Marsh good trick!
I decided to check if it is possible to directly set the zoom and the position of the center of the image (i.e. if it is possible to make it work in any case, even with overscroll enabled). Maybe someone will need this code:
#target photoshop
var s2t = stringIDToTypeID,
zoom = 0.5;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('resolution'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var res = executeActionGet(r).getInteger(p);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('width'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var docW = executeActionGet(r).getDouble(p) * res / 72;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('height'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var docH = executeActionGet(r).getDouble(p) * res / 72;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('zoom'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor()).putReference(s2t('null'), r);
(d1 = new ActionDescriptor()).putUnitDouble(s2t('zoom'), s2t('percentUnit'), zoom);
d.putObject(s2t('to'), p, d1);
executeAction(s2t('set'), d, DialogModes.NO);
(r = new ActionReference).putProperty(s2t('property'), s2t('center'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor).putReference(s2t('target'), r);
(d1 = new ActionDescriptor()).putUnitDouble(s2t('horizontal'), s2t('distanceUnit'), docW * zoom / 2);
d1.putUnitDouble(s2t('vertical'), s2t('distanceUnit'), docH * zoom / 2);
d.putObject(s2t('to'), s2t('center'), d1);
executeAction(s2t('set'), d, DialogModes.NO);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
From how you describe it, it sounds like you may just need to uncheck "overscroll" in Preferences?