Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I Horizontally Flip a layer in Photoshop using a script?

New Here ,
Jan 15, 2016 Jan 15, 2016

Assuming that the layer name is "Layer 0", how I flip it horizontally or vertically?, keeping the anchor point in center

TOPICS
Actions and scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Contributor ,
Jan 15, 2016 Jan 15, 2016

You can accomplish everything with ScriptingListener

this and for horizontal

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc22 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref9 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref9.putProperty( idChnl, idfsel );

    desc22.putReference( idnull, ref9 );

    var idT = charIDToTypeID( "T   " );

    var idOrdn = charIDToTypeID( "Ordn" );

    var idAl = charIDToTypeID( "Al  " );

    desc22.putEnumerated( idT, idOrdn, idAl );

executeAction( idsetd, desc22, DialogModes.NO );

// =======================================================

var idTrnf = charIDToTypeID( "Trnf" );

    var desc23 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref10 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref10.putEnumerated( idLyr, idOrdn, idTrgt );

    desc23.putReference( idnull, ref10 );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc23.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc24 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc24.putUnitDouble( idHrzn, idPxl, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc24.putUnitDouble( idVrtc, idPxl, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc23.putObject( idOfst, idOfst, desc24 );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc23.putUnitDouble( idWdth, idPrc, -100.000000 );

    var idIntr = charIDToTypeID( "Intr" );

    var idIntp = charIDToTypeID( "Intp" );

    var idBcbc = charIDToTypeID( "Bcbc" );

    desc23.putEnumerated( idIntr, idIntp, idBcbc );

executeAction( idTrnf, desc23, DialogModes.NO );

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc25 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref11 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref11.putProperty( idChnl, idfsel );

    desc25.putReference( idnull, ref11 );

    var idT = charIDToTypeID( "T   " );

    var idOrdn = charIDToTypeID( "Ordn" );

    var idNone = charIDToTypeID( "None" );

    desc25.putEnumerated( idT, idOrdn, idNone );

executeAction( idsetd, desc25, DialogModes.NO );

this for the vertical

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc26 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref12 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref12.putProperty( idChnl, idfsel );

    desc26.putReference( idnull, ref12 );

    var idT = charIDToTypeID( "T   " );

    var idOrdn = charIDToTypeID( "Ordn" );

    var idAl = charIDToTypeID( "Al  " );

    desc26.putEnumerated( idT, idOrdn, idAl );

executeAction( idsetd, desc26, DialogModes.NO );

// =======================================================

var idTrnf = charIDToTypeID( "Trnf" );

    var desc27 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref13 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref13.putEnumerated( idLyr, idOrdn, idTrgt );

    desc27.putReference( idnull, ref13 );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc27.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc28 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc28.putUnitDouble( idHrzn, idPxl, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc28.putUnitDouble( idVrtc, idPxl, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc27.putObject( idOfst, idOfst, desc28 );

    var idHght = charIDToTypeID( "Hght" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc27.putUnitDouble( idHght, idPrc, -100.000000 );

    var idIntr = charIDToTypeID( "Intr" );

    var idIntp = charIDToTypeID( "Intp" );

    var idBcbc = charIDToTypeID( "Bcbc" );

    desc27.putEnumerated( idIntr, idIntp, idBcbc );

executeAction( idTrnf, desc27, DialogModes.NO );

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc29 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref14 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref14.putProperty( idChnl, idfsel );

    desc29.putReference( idnull, ref14 );

    var idT = charIDToTypeID( "T   " );

    var idOrdn = charIDToTypeID( "Ordn" );

    var idNone = charIDToTypeID( "None" );

    desc29.putEnumerated( idT, idOrdn, idNone );

executeAction( idsetd, desc29, DialogModes.NO );

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 15, 2016 Jan 15, 2016

This might be easier.

  • flipLayer('v'); 
  • //flipLayer('h'); 
  •   
  • function flipLayer(direction) { 
  • switch (direction.toLowerCase()){ 
  •     case 'h' : direction = 'Hrzn'; break; 
  •     case 'v' : direction = 'Vrtc'; break; 
  •     default : return; 
  •     } 
  •     var desc23 = new ActionDescriptor(); 
  •     desc23.putEnumerated( charIDToTypeID('Axis'), charIDToTypeID('Ornt'), charIDToTypeID(direction) ); 
  • try{ 
  •     executeAction( charIDToTypeID('Flip'), desc23, DialogModes.NO ); 
  • }catch(e){} 
  • };


This is from this thread..

https://forums.adobe.com/thread/932286

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2016 Jan 15, 2016

SuperMerlin‌

I tried that, but it doesn't let me target a specific layer by name. It be default flips the bottom layer, any workaround?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 15, 2016 Jan 15, 2016
LATEST

It works on the active layer, you must select the layer first.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines