Copy link to clipboard
Copied
We've been using the below Java code to set the zoom of a document in Photoshop 7 (yeah, I know - ancient) to fit the screen (like hitting Ctrl + 0 on the PC) but it no longer works in CS6. The runMenuItem command is generating "Error 1242: Illegal argument - argument 1."
function runMenuItem(item){ // from xbytor
cTID = function(s) { return charIDToTypeID(s); };
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( cTID( "Mn " ), cTID( "MnIt" ), cTID( item ) );
desc.putReference( cTID( "null" ), ref );
executeAction( cTID( "slct" ), desc, DialogModes.NO );
}
runMenuItem("FtOn");// fit on screen ( same as ctrl-0 )
Is there some other way this can to be done in CS6?
Thanks,
Ken
app.runMenuItem(charIDToTypeID(("FtOn")));
Newer versions of Photoshop have an application method for calling menu items.
Copy link to clipboard
Copied
app.runMenuItem(charIDToTypeID(("FtOn")));
Newer versions of Photoshop have an application method for calling menu items.
Copy link to clipboard
Copied
That worked perfectly Michael, thanks so much.
I did a quick search but didn't find anything by way of a list of these. I found one reference that mentioned a PDF in which the ScriptListener was described. I've download it and am about to give it a try.
Do you know if there IS, indeed, a list of these somewhere?
Again, many thanks,
Ken
Copy link to clipboard
Copied
There are a couple of lists but I think the best way to find the IDs you need is to use the scriptlistener plug-in for things that can be recorded to the log. Some things don't log, so for those you can try using 'insert menu item' in an action, save the action, then either look at the action file with an hex editor or use xbytor's xtools to convert the action file to javascript.
Here is a list of view related IDs
charIDToTypeID("FtOn"); // fit window
charIDToTypeID("ActP"); // actual pixels
charIDToTypeID("ZmIn"); // zoom in
charIDToTypeID("ZmOt"); // zoom out
stringIDToTypeID("screenModeFullScreen");
stringIDToTypeID ("screenModeStandard");
stringIDToTypeID( "screenModeFullScreenWithMenubar" );
Copy link to clipboard
Copied
Current version of Photoshop CC, 14.1.2, will let you set the zoom factor. You can also get the zoom factor and get the point at which the document is zoomed at, keyCenter.
const classProperty = app.charIDToTypeID('Prpr');
const kzoomStr = app.stringIDToTypeID("zoom");
const classDocument = app.charIDToTypeID('Dcmn');
const typeOrdinal = app.charIDToTypeID('Ordn');
const enumTarget = app.charIDToTypeID('Trgt');
const typeNULL = app.charIDToTypeID('null');
const keyTo = app.charIDToTypeID('T ');
const eventSet = app.charIDToTypeID('setd');
const enumZoom = app.charIDToTypeID('Zm ');
const unitPercent = app.charIDToTypeID('#Prc');
for ( var i = 0; i < 10; i++ ) {
// =======================================================
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( classProperty, kzoomStr );
ref.putEnumerated( classDocument, typeOrdinal, enumTarget );
desc.putReference( typeNULL, ref );
var toDesc = new ActionDescriptor();
toDesc.putUnitDouble(enumZoom, unitPercent, i);// 3.333333);
desc.putObject( keyTo, kzoomStr, toDesc );
executeAction( eventSet, desc, DialogModes.NO );
app.refresh();
}
Copy link to clipboard
Copied
Hi Tom
Besides zoom factor, be able to get and put keyCenter point would be an impressive improvement for our huge work flow.
1. But I want to know if it is only to 'get' x,y keyCenter point? Could also this set by script (not only get)?
2. Meanwhile we have many problems adapting our CS6 workflow scripts to CC and we are forced to use CS6 at least for a year. Is it to much to ask if CS6 zoom could have this also?
My god, this would avoid so many 'inteligent zoom' considering we that we have script auto-detection to wich part of an image we need to zoom and how much.
And also another old idea: I could create a script with a UI window (activeDocument thumb exported to Folder.temp), geting the thumb on window and click to the point to zoom (I can get x,y point on image UI) and if the image is pressed like a button.onClick it closes window and zoom exactly to that point.
The time consumed in using inner zoom tool (mouse or pad dependent with drags and cliks) if has the chance to be shortened using a '1 click script', is a major issue for huge workflows.
Copy link to clipboard
Copied
Slightly older topic, but zoom to selection would be awfully handy. Can anybody describe from Tom's code above how to get the keyCenter value?
Copy link to clipboard
Copied
Hi Tom,
any chance to have scriptable panning too (e.g. moving horizontal/vertical scrollbars)?
Thank you!
Davide Barranca
---
www.davidebarranca.com
www.cs-extensions.com
Copy link to clipboard
Copied
These scripts work in CS6 (at the very least), and will set your zoom levels to 6.25, 8.33, 12.5, 50, 66.67, 100, 200 respectively.
6.25%
function getScreenRes(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}
function setZoom( zoom ) {
cTID = function(s) { return app.charIDToTypeID(s); };
var docRes = activeDocument.resolution;
activeDocument.resizeImage( undefined, undefined, getScreenRes()/(zoom/399.7), 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 (25);
8.33%
function getScreenRes(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}
function setZoom( zoom ) {
cTID = function(s) { return app.charIDToTypeID(s); };
var docRes = activeDocument.resolution;
activeDocument.resizeImage( undefined, undefined, getScreenRes()/(zoom/300.1), 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 (25);
12.5%
function getScreenRes(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}
function setZoom( zoom ) {
cTID = function(s) { return app.charIDToTypeID(s); };
var docRes = activeDocument.resolution;
activeDocument.resizeImage( undefined, undefined, getScreenRes()/(zoom/200.0), 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 (25);
50%
function getScreenRes(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}
function setZoom( zoom ) {
cTID = function(s) { return app.charIDToTypeID(s); };
var docRes = activeDocument.resolution;
activeDocument.resizeImage( undefined, undefined, getScreenRes()/(zoom/50), 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 (25);
66.67%
function getScreenRes(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;
}
function setZoom( zoom ) {
cTID = function(s) { return app.charIDToTypeID(s); };
var docRes = activeDocument.resolution;
activeDocument.resizeImage( undefined, undefined, getScreenRes()/(zoom/37.5), 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 (25);
100%
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
doMenuItem = function(item, interactive) {
var ref = new ActionReference();
ref.putEnumerated(cTID("Mn "), cTID("MnIt"), item);
var desc = new ActionDescriptor();
desc.putReference(cTID("null"), ref);
try {
var mode = (interactive != true ? DialogModes.NO : DialogModes.ALL);
executeAction(sTID("select"), desc, mode);
} catch (e) {
if (!e.message.match("User cancelled")) {
throw e;
} else {
return false;
}
}
return true;
}
doMenuItem(cTID('ActP')); // Set Zoom to 100%
;doMenuItem(cTID('ZmIn')); // Zoom in on time more. (100 %)
200%
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
doMenuItem = function(item, interactive) {
var ref = new ActionReference();
ref.putEnumerated(cTID("Mn "), cTID("MnIt"), item);
var desc = new ActionDescriptor();
desc.putReference(cTID("null"), ref);
try {
var mode = (interactive != true ? DialogModes.NO : DialogModes.ALL);
executeAction(sTID("select"), desc, mode);
} catch (e) {
if (!e.message.match("User cancelled")) {
throw e;
} else {
return false;
}
}
return true;
}
doMenuItem(cTID('ActP')); // Set Zoom to 100%
doMenuItem(cTID('ZmIn')); // Zoom in on time more. (200 %)
Copy link to clipboard
Copied
Now if we could just set the keycenter value...