What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Scripting Reverse Order of Layers


revnart

Power User
Messages
362
Likes
327
Hi, maybe I'm not the only one, whit this problem. When i have layers like this:
Zrzut ekranu 2018-07-30 o 14.34.13.png

and go to Layer > Arrange > Reverse (I have selected all layers before that step :p )

I get error:

Zrzut ekranu 2018-07-30 o 14.34.46.png

The only solution is to make one layer at top of the layers stack, then one in the bottom of layers stack, select layers between those two and it works without problems :)

I was a little frustrated so I created small script that helps reversing order of layers. No rocket science, probably can be done better, more efficient and so on - but for me is enough, posting it here beceuse someone may find it useful.

One note only: it will not work with groups ;)

JavaScript:
var layers = app.activeDocument.artLayers.length;

for (var i = 1; i < app.activeDocument.artLayers.length; i++)
{
//  SELECT MOST BOTTOM LAYER
var idslct = charIDToTypeID( "slct" );
    var desc16 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref16 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBack = charIDToTypeID( "Back" );
        ref16.putEnumerated( idLyr, idOrdn, idBack );
    desc16.putReference( idnull, ref16 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc16.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list12 = new ActionList();
        list12.putInteger( 3 );
    desc16.putList( idLyrI, list12 );
executeAction( idslct, desc16, DialogModes.NO );

// MOVE ONE LAYER UP
for (var x = 0; x < app.activeDocument.artLayers.length - i ; x++) {
var idmove = charIDToTypeID( "move" );
    var desc67 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref41 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref41.putEnumerated( idLyr, idOrdn, idTrgt );
    desc67.putReference( idnull, ref41 );
    var idT = charIDToTypeID( "T   " );
        var ref42 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idNxt = charIDToTypeID( "Nxt " );
        ref42.putEnumerated( idLyr, idOrdn, idNxt );
    desc67.putReference( idT, ref42 );
executeAction( idmove, desc67, DialogModes.NO );
}}


result:
Zrzut ekranu 2018-07-30 o 14.35.01.png
 
and go to Layer > Arrange > Reverse (I have selected all layers before that step )

I get error:
The function works great for me. I'm running PsCC 19.1.5
This should work for you as well without having to use a script. Have you tried all of the usual fixes?
 
yes, on windows and on osx I have the same issue, preferences cleared etc. Will talk with my company staff, to update Photoshop to latest version ;) maybe here lies the problem ;)
 
Not newest, since I see that update is available, but I don't have authorization to update it. Will be at work tomorrow and will check ;)
 
Everything works fine for me, no problem with that function, PS 19.1.5 on win10...
 
Last edited:

Back
Top