Copy link to clipboard
Copied
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); }
}
Copy link to clipboard
Copied
For your exact need you can rewrite script (in some later post) that will do the same in CS6:
Copy link to clipboard
Copied
This is not convenient for documents with layers effects or smart objects with filters
Copy link to clipboard
Copied
Do you know if "viewTransform" property is set-able?
It contains 2D matrix of document view transfomation including scale, translate and rotation.
It could look something like this but I am not sure how to use "set" action with "actionList"
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("viewTransform"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionList();
d1.putDouble(2);
d1.putDouble(0);
d1.putDouble(0);
d1.putDouble(2);
d1.putDouble(-17);
d1.putDouble(-18);
d.putList(stringIDToTypeID("to"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
Copy link to clipboard
Copied
No, I can not set it
I found one more similar property. Also read only.
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("transform"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
// or
// r.putClass(stringIDToTypeID("transform"));
// or
// r.putIndex(stringIDToTypeID("transform"), 1111111111111);
ret = executeActionGet(r).getList(stringIDToTypeID("toWindow"));
Also found that the property stringIDToTypeID("viewInfo") in the document is probably better suited for scrolling
than the application property stringIDToTypeID("documentArea").
Did not check.
Copy link to clipboard
Copied
I think "viewInfo" is CC2018 only. I think they added it because of "Learn panel" needs fancy toolTips with exact location.
Copy link to clipboard
Copied
It would be cool a gif to illustrate better, this seems to be very useful.
It would be nice to have multiple documents in "tile all vertically" mode with a zoom that shows all the documents completely.
Copy link to clipboard
Copied
Updated simplified and working version of set_doc_position.
Now it works with floating document windows.
set_doc_position(0, 0)
//set_doc_position(100, -220)
function set_doc_position(x, y)
{
try {
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("viewInfo"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("viewInfo")).getObjectValue(stringIDToTypeID("activeView")).getObjectValue(stringIDToTypeID("globalBounds"));
var b = new Array();
b[0] = bounds.getUnitDoubleValue(stringIDToTypeID("left"));
b[1] = bounds.getUnitDoubleValue(stringIDToTypeID("top"));
b[2] = bounds.getUnitDoubleValue(stringIDToTypeID("right"));
b[3] = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));
var dx = 8; // what is it?
var dy = 8; // what is it?
x = (b[2]-b[0])/2 - x - dx;
y = (b[3]-b[1])/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); }
}
UPD. Fixed a bug in the script. The document moved in the opposite direction x and y.
Copy link to clipboard
Copied
hi,r-bin:
Excuse me ,How do you know the document properties include “viewInfo”?
i tried to reflect the document and could not get the “Viewinfo” properties。
function reflectProps(obj) {
var props = obj.reflect.properties;
var reflect= obj.reflect;
alert( obj.reflect.description)
alert( obj.reflect.help)
alert( obj.reflect.name)
alert( obj.reflect.sampleCode)
alert( obj.reflect.staticProperties)
for (var i = 0, len = props.length; i < len; i++) {
try {
$.writeln(props[i].name + ' = ' + obj[props[i].name]);
WriteData(props[i].name + ' = ' + obj[props[i].name])
} catch (e) {}
}
}
function reflectMeths(obj) {
var meths = obj.reflect.methods;
for (var i = 0, len = meths.length; i < len; i++) {
try {
$.writeln(meths[i].name + '();');
WriteData(meths[i].name + '();')
} catch (e) {}
}
}
function WriteData(Txt)
{
var file = new File(Folder.desktop + "/rflection.txt");
file.open("a", "TEXT",null);
file.encoding = "UTF8";
file.seek(0,2);
$.os.search(/windows/i) != -1 ? file.lineFeed = 'windows' : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
}
// Example of use:
var r = new ActionReference();
var d = new ActionDescriptor();
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(charIDToTypeID('null'), r);
var options = executeAction(charIDToTypeID( "getd" ), d, DialogModes.NO);
var lay =options;
WriteData("\n*************** properties **********************\n")
reflectProps(lay);
WriteData("\n*************** methods **********************\n")
reflectMeths(lay);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Is that how it's used?There's no “viewInfo” 。
var r = new ActionReference();
var d = new ActionDescriptor();
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(charIDToTypeID('null'), r);
var options = executeAction(charIDToTypeID( "getd" ), d, DialogModes.NO);
var nameall;
for (var i = 0; i < options.count; i++)
{
if(options.typename=="ActionList" )
var key = i;
else
var key = options.getKey(i);
var proname = typeIDToStringID(key);
if (!proname)
proname = typeIDToCharID(key);
nameall=nameall+"\n"+key+":"+proname;
}
WriteData(nameall)
/***************** WriteData Function************************************************/
function WriteData(Txt)
{
var file = new File(Folder.desktop + "/data_tem1.txt");
file.open("a", "TEXT",null);
file.encoding = "UTF8";
file.seek(0,2);
$.os.search(/windows/i) != -1 ? file.lineFeed = 'windows' : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
}
result:
undefined
1298407456:mode
1114066504:bigNudgeH
1114066518:bigNudgeV
1382838856:rulerOriginH
1382838870:rulerOriginV
1466201192:width
1214736500:height
1383296116:resolution
1416916000:title
1181501806:fileInfo
1315791440:numberOfPaths
1315791439:numberOfChannels
1315791436:numberOfLayers
1416783696:targetPathIndex
1467116368:workPathIndex
1131180135:clippingPathInfo
1148220520:depth
1148150601:documentID
1131444594:copyright
2002875506:watermark
1232290930:isDirty
1131312160:count
1232366921:itemIndex
420:manage
3147:workflow
1366647629:quickMask
1215525991:histogram
1276:pixelScaleFactor
3148:XMPMetadataAsUTF8
1280:measurementScale
3151:targetLayers
3153:targetLayersIDs
3152:targetLayersIndexes
1517101088:zoom
3155:printCopies
788:printCurrentPrinter
3156:printerList
3157:printColorHandling
1265:printOutputOptions
1267:printOutput
1131312242:center
3158:hasBackgroundLayer
3182:generatorSettings
3191:targetPathVisibility
3192:guidesVisibility
3193:smartGuidesVisibility
3194:rulersVisibility
Copy link to clipboard
Copied
var strings = ["viewInfo", "viewTransform", /*... and so on*/ ];
// how to get all strings
for (var i = 0; i < 0xFFFFFFFF; i++)
{
var s = typeIDToStringID(i);
if (s) strings.push(s);
}
// test if property exists in document
for (var i = 0; i < strings.length; i++)
{
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID(strings[i]);
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var ok = true;
try { var result = executeActionGet(r); } catch (e) { ok = false; }
if (ok) alert(strings[i] + " exists in document");
}
Copy link to clipboard
Copied
Thank you for your reply,This is very effective
Copy link to clipboard
Copied
After 2 years it's still good topic. Here's brute force results:
Document saved property not updating when manipulating guides
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Yes there's only some 'getViewInfo' on your list.
btw 'viewInfo2' appears after I put the 'viewInfo' property and then executeGetAction:
documents.add(), sTT = stringIDToTypeID;
(ref = new ActionReference()).putProperty(sTT('property'), sTT('viewInfo'))
ref.putEnumerated(sTT('document'), sTT('ordinal'), sTT('targetEnum'));
(dsc = executeActionGet(ref)).putInteger(sTT(0), 3326)
typeIDToStringID(dsc.getInteger(sTT(0)))
I did that after launching CC 2020 so maybe that'll be a little other number than 3326 for you.
Copy link to clipboard
Copied
Some other thread recently lead me back to this one and it got me to thinking about some old request for »session saving« in Photoshop. I can’t locate it at the moment, but basically it was about being able to re-open the opened images and restore the way they were arranged on the screen at a given time.
Saving a list of fullNames is easy enough and code in this thread seems to handle zoom just fine, but window positions still seem unclear to me.
Have any of you managed to set a window’s position on the screen via Script?
Copy link to clipboard
Copied
Before you set relocate images on screen are you able to read their positions?
Copy link to clipboard
Copied
»are you able to read their positions?«
Yes, in r-bin’s code there is the line
var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("viewInfo")).getObjectValue(stringIDToTypeID("activeView")).getObjectValue(stringIDToTypeID("globalBounds"));
that gets a floating document’s position.
»It is not clear what to do if the document is in a tab, or in a tab in a floating window. Also, a lot depends on the Photoshop mode (fullscreen, etc).«
Good points, as so often the issue is more complicated than I initially assumed …
Copy link to clipboard
Copied
I tried writing new values for globalBounds and nothing worked for me 😞
(d = new ActionDescriptor()).putDouble(s2t('left'), 200);
d.putDouble(s2t('top'), 200);
d.putDouble(s2t('bottom'), 400);
d.putDouble(s2t('right'), 400);
(d1 = new ActionDescriptor()).putObject(s2t('globalBounds'), s2t('null'), d);
(d2 = new ActionDescriptor()).putObject(s2t('activeView'), s2t('null'), d1);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('viewInfo'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
(d3 = new ActionDescriptor).putReference(s2t('null'), r);
d3.putObject(s2t('to'), p, d2);
executeAction(s2t('set'), d3, DialogModes.NO);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for the feedback!
I found the thread I vaguely recalled but the term used was not »sessions«.
Photoshop: Save/Reopen projects/collections of files and save window positions