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

Modify a “LayerEffects” object

Community Beginner ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

Hi All,

Im attempting to write a script that can automate the process of changing a RGB colour of a layerEffect - such as stroke, dropshadow or coloroverlay.

Im aware it is ActionManager code that can accomplish this. Has anyone got any ideas of how to "modify" the existing set of layerEffects and target only the correct effect,  as Ive only been able to get so far as updating the new color, but it deletes all the other existing layerEffects.

If copying the whole layerEffects object is required, then modifying the correct component and then pasting it back onto that layer is required, any assistance or ideas of how to accomplish this would be much appreciated.

Thanks in advance.

TOPICS
Actions and scripting

Views

1.1K

Translate

Translate

Report

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

correct answers 1 Correct answer

Guide , Jul 23, 2021 Jul 23, 2021

@Symo470 I don’t know what’s the matter, but the restriction on sending private messages is regularly triggered for me. 

2021-07-23_22-08-27.png

You asked in a private message about replacing colors in gradients. With a gradient, the principle is the same, just a little more steps when assembling an object. First, we get each element of the object and save it to a variable, then we set new colors and put everything in reverse order.

The only thing is that the gradient object is more complicated than the fill, so a simple

...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

As I said, the problem is not only in setLayerStyle, but in getLayerStyle, which incorrectly returns layer styles. And it can return different things every time.

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

I think Ive identified what you've stated.

I run my script several times using getLaterStyle and setLayerStyle and it can produce different results each time.

Where do we start to get this updated for PS 2020 and beyond?

Votes

Translate

Translate

Report

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 ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

@Symo470 I don’t know what’s the matter, but the restriction on sending private messages is regularly triggered for me. 

2021-07-23_22-08-27.png

You asked in a private message about replacing colors in gradients. With a gradient, the principle is the same, just a little more steps when assembling an object. First, we get each element of the object and save it to a variable, then we set new colors and put everything in reverse order.

The only thing is that the gradient object is more complicated than the fill, so a simple color change is not enough here: you must definitely compare the number of colors in the gradient and the arguments passed to the function (in the example, replace colors in any three-color gradient) in order to preserve the integrity of the object. And the multi-effect is more difficult to process (the example simply ignores this situation, although you can, for example, take only the first gradient from the list and replace the colors in it).

 

changeFill([255, 0, 0], [0, 255, 0], [0, 0, 255]); // [R, G, B] values

function changeFill() {
    s2t = stringIDToTypeID;

    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerEffects'));
    r.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
    if (executeActionGet(r).hasKey(p)) var fx = executeActionGet(r).getObjectValue(p);

    if (fx && fx.hasKey(p = s2t('gradientFill'))) {
        var gradientFill = fx.getObjectValue(p),
            gradient = gradientFill.getObjectValue(s2t('gradient')),
            colors = gradient.getList(s2t('colors'));

        if (arguments.length == colors.count) {
            var newColors = new ActionList();
            for (var i = 0; i < colors.count; i++) {
                var currentColor = colors.getObjectValue(i);
                (d = new ActionDescriptor()).putDouble(s2t('red'), arguments[i][0]);
                d.putDouble(s2t('green'), arguments[i][1]);
                d.putDouble(s2t('blue'), arguments[i][2]);
                currentColor.putObject(s2t('color'), s2t('RGBColor'), d)
                newColors.putObject(s2t('colorStop'), currentColor)
            }

            gradient.putList(s2t('colors'), newColors)
            gradientFill.putObject(s2t('gradient'), s2t('gradientClassEvent'), gradient);
            fx.putObject(s2t('gradientFill'), s2t('gradientFill'), gradientFill);
            (d = new ActionDescriptor()).putReference(s2t('null'), r);
            d.putObject(s2t('to'), s2t('layerEffects'), fx);
            executeAction(s2t('set'), d, DialogModes.NO);
        }
    }
}

 

Ask questions on the public platform of the forum, put likes, mark the right solutions to help other users find answers on similar questions - this is the best way.

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 30, 2021 Jul 30, 2021

Copy link to clipboard

Copied

LATEST

@Symo470  – Please mark one or multiple answers as correct so that others with the same/similar question know that an answer was found.

Votes

Translate

Translate

Report

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