Skip to main content
999tevashkevich
Known Participant
May 2, 2016
Question

PS Scripting - ApplyStyle

  • May 2, 2016
  • 5 replies
  • 2021 views

Hey everyone,

I've been trying and searching and can not get this to work at all on any layer.

What I'm trying to accomplish is

Apply the Color Overlay layer style to a selected layer

Set Color Overlay blendmode to Linear Burn

Set Color Overlay color to 255,255,128 (RGB)

That's it but I can't even get the layer to apply Color Overlay, it just says that it doesn't work (the general photoshop error as usual with Scripting errors...)

I'd love to do a write up of getting the layer styles to work so others can use it as well (since I haven't come across anything in my searches)

Thanks for any help

PS:

I know about the listener code and have the code in hand, I'm just wondering how to do without the listener garbage code...

This topic has been closed for replies.

5 replies

Chuck Uebele
Community Expert
Community Expert
May 3, 2016

This removes all effects:

var iddlfx = charIDToTypeID( "dlfx" );

    var desc13 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref2.putEnumerated( idLyr, idOrdn, idTrgt );

    desc13.putReference( idnull, ref2 );

executeAction( iddlfx, desc13, DialogModes.NO );

999tevashkevich
Known Participant
May 3, 2016

The weird thing is that if I run the code to hide or even delete the layer effect it works as long as I RUN it from the extendscript toolkit.  If I run it via the script list inside photoshop it doesn't hide/delete. Any ideas?

Chuck Uebele
Community Expert
Community Expert
May 3, 2016

That's odd. I had no trouble running the code I posted from PS. What version of PS are you using, and do you have the target tag at the beginning of the script, and if so you have just that and no version number?

#target photoshop

999tevashkevich
Known Participant
May 3, 2016

This is the thing guys, I need to DISABLE the layer style now. I've had the listener code to turn it on since yesterday but there's nothing that seems to turn it off (even with the "Hd  " as the flag for example)

JJMack
Community Expert
Community Expert
May 3, 2016

I add a color overlay layer style to a Layer. I the turned on the scriptlistener recorder click the eye one the Layer effect to hade all the layer style effect and clicked a second to turn them back on and turn off the scriptlistener recorder.  Here are the two steps I recorded.

The first one should hide the current layers style effects. All of them

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

var idHd = charIDToTypeID( "Hd  " );

    var desc31 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list7 = new ActionList();

            var ref12 = new ActionReference();

            var idLefx = charIDToTypeID( "Lefx" );

            ref12.putClass( idLefx );

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref12.putEnumerated( idLyr, idOrdn, idTrgt );

        list7.putReference( ref12 );

    desc31.putList( idnull, list7 );

executeAction( idHd, desc31, DialogModes.NO );

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

var idShw = charIDToTypeID( "Shw " );

    var desc32 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list8 = new ActionList();

            var ref13 = new ActionReference();

            var idLefx = charIDToTypeID( "Lefx" );

            ref13.putClass( idLefx );

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref13.putEnumerated( idLyr, idOrdn, idTrgt );

        list8.putReference( ref13 );

    desc32.putList( idnull, list8 );

executeAction( idShw, desc32, DialogModes.NO );

JJMack
JJMack
Community Expert
Community Expert
May 3, 2016

These are the two that were recorded when I just hid and show the color overlay effect.

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

var idHd = charIDToTypeID( "Hd  " );

    var desc33 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list9 = new ActionList();

            var ref14 = new ActionReference();

            var idSoFi = charIDToTypeID( "SoFi" );

            ref14.putIndex( idSoFi, 1 );

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref14.putEnumerated( idLyr, idOrdn, idTrgt );

        list9.putReference( ref14 );

    desc33.putList( idnull, list9 );

executeAction( idHd, desc33, DialogModes.NO );

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

var idShw = charIDToTypeID( "Shw " );

    var desc34 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list10 = new ActionList();

            var ref15 = new ActionReference();

            var idSoFi = charIDToTypeID( "SoFi" );

            ref15.putIndex( idSoFi, 1 );

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref15.putEnumerated( idLyr, idOrdn, idTrgt );

        list10.putReference( ref15 );

    desc34.putList( idnull, list10 );

executeAction( idShw, desc34, DialogModes.NO );

JJMack
JJMack
Community Expert
Community Expert
May 3, 2016

I find that layer style effect are set via absolute pixel value settings that would need to be changed for different resolution images. I also find the when you save a layer style it goes in the styles palette and Adobe records the resolution of the image you save the style for.  That when you apple the style to a document layer Photoshop scales the style effects for the current document relative to the stored resolution in the named layer style.  So What I do is to save a set of named layer style and send these out with my scripts.  In the Script Dialog I provide a Pull-down menu user can use to select my styles.  My script add layer styles via named layer style.

function addStyle(Style){

  var idASty = charIDToTypeID( "ASty" );

     var desc20 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref3 = new ActionReference();

         var idStyl = charIDToTypeID( "Styl" );

         ref3.putName( idStyl, Style );               // <==================

     desc20.putReference( idnull, ref3 );

     var idT = charIDToTypeID( "T   " );

         var ref4 = new ActionReference();

         var idLyr = charIDToTypeID( "Lyr " );

         var idOrdn = charIDToTypeID( "Ordn" );

         var idTrgt = charIDToTypeID( "Trgt" );

         ref4.putEnumerated( idLyr, idOrdn, idTrgt );

     desc20.putReference( idT, ref4 );

  try{

  executeAction( idASty, desc20, DialogModes.NO);

  }catch(e){}

}

JJMack
May 3, 2016

You may want to have a look at the jamStyles module of my JSON Action Manager library.

Applying the color overlay effect with specific blending mode to the currently selected layer could be written that way (making use of the Blending Options Object Simplified Format and the Layer Effects Object Simplified Format):

var layerStyleObj =

{

    "layerEffects":

    {

        "solidFill":

        {

            "mode": "linearBurn",

            "color": { "red": 255, "green": 255, "blue": 128 }

        }

    }

};

jamStyles.setLayerStyle (layerStyleObj);

Please refer to the Layer Styles Quick Tutorial for more "how-to" code examples.

HTH,

--Mikaeru

999tevashkevich
Known Participant
May 3, 2016

I've looked at your libs (quite a few times) and they look awesome, I just haven't gotten around to trying to pack them (or do the copy all code into one file thing) but I might have to just for this if I can't get this figured out.

Chuck Uebele
Community Expert
Community Expert
May 2, 2016

If the listener code works, use it. Somethings just don't work otherwise, and the AM code works faster too. Not worth banging your head against the wall.

999tevashkevich
Known Participant
May 2, 2016

It does work I just like to be able to have clean code if possible and like I said too, I would like to be able to "document" it for others later.

I'll probably end up using listener garbage anyways till/if we can figure it out

999tevashkevich
Known Participant
May 3, 2016

Ok, well actually I have the code to turn it all on. The listener code that should turn it off does not actually work which makes no sense at all...

var idsetd = charIDToTypeID( "setd" );

    var desc34 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref12 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idLefx = charIDToTypeID( "Lefx" );

        ref12.putProperty( idPrpr, idLefx );

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref12.putEnumerated( idLyr, idOrdn, idTrgt );

    desc34.putReference( idnull, ref12 );

    var idT = charIDToTypeID( "T   " );

        var desc35 = new ActionDescriptor();

        var idScl = charIDToTypeID( "Scl " );

        var idPrc = charIDToTypeID( "#Prc" );

        desc35.putUnitDouble( idScl, idPrc, 100.000000 );

    var idLefx = charIDToTypeID( "Lefx" );

    desc34.putObject( idT, idLefx, desc35 );

executeAction( idsetd, desc34, DialogModes.NO );

is what I got, but it doesn't make a lot of sense to me since there isn't a disable anywhere where as the code to turn on and do the layer blend mode does,

    var idsetd = charIDToTypeID( "setd" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idLefx = charIDToTypeID( "Lefx" );

        ref1.putProperty( idPrpr, idLefx );

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref1.putEnumerated( idLyr, idOrdn, idTrgt );

    desc2.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T   " );

        var desc3 = new ActionDescriptor();

        var idScl = charIDToTypeID( "Scl " );

        var idPrc = charIDToTypeID( "#Prc" );

        desc3.putUnitDouble( idScl, idPrc, 100.000000 );

        var idSoFi = charIDToTypeID( "SoFi" );

            var desc4 = new ActionDescriptor();

            var idenab = charIDToTypeID( "enab" );

            desc4.putBoolean( idenab, true );

            var idMd = charIDToTypeID( "Md  " );

            var idBlnM = charIDToTypeID( "BlnM" );

            var idlinearBurn = stringIDToTypeID( "linearBurn" );

            desc4.putEnumerated( idMd, idBlnM, idlinearBurn );

            var idOpct = charIDToTypeID( "Opct" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc4.putUnitDouble( idOpct, idPrc, 100.000000 );

            var idClr = charIDToTypeID( "Clr " );

                var desc5 = new ActionDescriptor();

                var idRd = charIDToTypeID( "Rd  " );

                desc5.putDouble( idRd, 255.000000 );

                var idGrn = charIDToTypeID( "Grn " );

                desc5.putDouble( idGrn, 255.000000 );

                var idBl = charIDToTypeID( "Bl  " );

                desc5.putDouble( idBl, 127.998047 );

            var idRGBC = charIDToTypeID( "RGBC" );

            desc4.putObject( idClr, idRGBC, desc5 );

        var idSoFi = charIDToTypeID( "SoFi" );

        desc3.putObject( idSoFi, idSoFi, desc4 );

    var idLefx = charIDToTypeID( "Lefx" );

    desc2.putObject( idT, idLefx, desc3 );

    executeAction( idsetd, desc2, DialogModes.NO );