Skip to main content
Legend
September 1, 2018
Question

Scripting for Zoom and Scroll in CC2018

  • September 1, 2018
  • 4 replies
  • 4341 views

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); }

    }

This topic has been closed for replies.

4 replies

c.pfaffenbichler
Community Expert
Community Expert
September 21, 2020

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? 

Kukurykus
Legend
September 21, 2020

Before you set relocate images on screen are you able to read their positions?

c.pfaffenbichler
Community Expert
Community Expert
September 22, 2020

»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 … 

r-binAuthor
Legend
September 1, 2018

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.

greless
Inspiring
September 2, 2020

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);

 

r-binAuthor
Legend
September 2, 2020
So you look at the contents of the ActionDescriptor object, there is nothing like that.
To get the keys and their values, you need to use the get ... methods (depending on the type of the key in the descriptor).
Such a moronic structure was invented when there were no scripts at all, and was used to record the parameters of Actions in Photoshop.

How did I know that there is a "viewInfo" key there?
By iterating over all known stringIDs and substituting it as "property" and see if there is a result or an error occurs.
 
Known Participant
September 1, 2018

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.

Kukurykus
Legend
September 1, 2018

For your exact need you can rewrite script (in some later post) that will do the same in CS6:

Performance of custom Zoom In script - PS-SCRIPTS.COM

r-binAuthor
Legend
September 1, 2018

This is not convenient for documents with layers effects or smart objects with filters

Jarda Bereza
Inspiring
September 1, 2018

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);