Scripting for Zoom and Scroll in CC2018
I do not know if anyone knows about such features or not in CC2018.
I just found a very useful feature.
It is a pity that I will not use it, because in CS6 it does not work,
and CC2018 is very buggy.
It was checked on Windows 7.
Screen resolution 1920x1080.
Photoshop is in windowed or maximized modes.
Documents in Photoshop are in Tabs Mode.
// set_doc_zoom(44.12) // sets zoom
// set_doc_position(0, 0) // sets top-left point of doc convas on the screen (scrolling)
function set_doc_zoom(zoom)
{
try {
if (!zoom) zoom = 100;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
d1.putDouble(stringIDToTypeID("zoom"), zoom/100);
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("zoom"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
function set_doc_position(x, y)
{
try {
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("documentArea"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var _l = executeActionGet(r).getObjectValue(stringIDToTypeID("documentArea")).getUnitDoubleValue(stringIDToTypeID("left"));
var _t = executeActionGet(r).getObjectValue(stringIDToTypeID("documentArea")).getUnitDoubleValue(stringIDToTypeID("top"));
var _r = executeActionGet(r).getObjectValue(stringIDToTypeID("documentArea")).getUnitDoubleValue(stringIDToTypeID("right"));
var _b = executeActionGet(r).getObjectValue(stringIDToTypeID("documentArea")).getUnitDoubleValue(stringIDToTypeID("bottom"));
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("workspacePreferences"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var large_tabs= executeActionGet(r).getObjectValue(stringIDToTypeID("workspacePreferences")).getBoolean(stringIDToTypeID("enableLargeTabs"));
var d1 = new ActionDescriptor();
d1.putBoolean(stringIDToTypeID("enableLargeTabs"), false);
var dx = 9; // some offset ??????
var dy = large_tabs?24:19; // ??????
x = (_r-_l)/2 + x - dx;
y = (_b-_t)/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 (e) { throw(e); }
}
