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

How to change the color of layer style color overlay from foreground color?

Explorer ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

How can I change the color of layer style color overlay, but using as reference the color from foreground color? Let's say I have a color overlay as 30% opacity and red. And I want to change it to the blue that is on my foreground color. Which class should I look for when dealing with color overlay from layer style?

 

Thanks in advance.

 

TOPICS
Actions and scripting

Views

1.2K

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

Community Expert , Apr 14, 2023 Apr 14, 2023

OK, thanks to @jazz-y (the link to the original topic is in the code), I believe that I have a workable solution:

 

/*
Change only the colour overlay layer style effect to the foreground colour
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-change-the-color-of-layer-style-color-overlay-from-foreground-color/td-p/13726891
*/

#target photoshop

var rValue = app.foregroundColor.rgb.red.toFixed(2),
    gValue = app.foregroundColor.rgb.green.toFixed(2),
    bValue = app.foregr
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

@marior90336416 

 

This isn't covered in the DOM. How Adobe implemented Layer Styles is tricky, we can't always use the "simple" Action Manager (AM) code generated by ScriptingListener verbatim, as it records the entire layer styles, when all we wish to do is change a single property of a single effect.

 

You will need to use some advanced Action Manager code.  

 

Searching the forum or web would be a good place to start.

 

To get the R, G, B foreground colours as variables to "plug into" something:

 

var rValue = app.foregroundColor.rgb.red.toFixed(2);
var gValue = app.foregroundColor.rgb.green.toFixed(2);
var bValue = app.foregroundColor.rgb.blue.toFixed(2);

 

 

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

OK, thanks to @jazz-y (the link to the original topic is in the code), I believe that I have a workable solution:

 

/*
Change only the colour overlay layer style effect to the foreground colour
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-change-the-color-of-layer-style-color-overlay-from-foreground-color/td-p/13726891
*/

#target photoshop

var rValue = app.foregroundColor.rgb.red.toFixed(2),
    gValue = app.foregroundColor.rgb.green.toFixed(2),
    bValue = app.foregroundColor.rgb.blue.toFixed(2);

changeFill(rValue, gValue, bValue);

function changeFill(red, green, blue) {
    /* https://community.adobe.com/t5/photoshop-ecosystem-discussions/modify-a-layereffects-object/td-p/12170579#U12194548 */ 
    s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t("property"), p = s2t("layerEffects"));
    r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    var fx = executeActionGet(r).hasKey(p) ? executeActionGet(r).getObjectValue(p) : new ActionDescriptor(),
        currentFill = fx.hasKey(p = s2t("solidFill")) ? fx.getObjectValue(p) : new ActionDescriptor();
    if (fx.hasKey(p = s2t("solidFillMulti"))) fx.erase(p);
    (d = new ActionDescriptor()).putDouble(s2t("red"), red);
    d.putDouble(s2t("green"), green);
    d.putDouble(s2t("blue"), blue);
    currentFill.putObject(s2t("color"), s2t("RGBColor"), d);
    fx.putObject(s2t("solidFill"), s2t("solidFill"), currentFill);
    (r = new ActionReference()).putProperty(s2t("property"), s2t("layerEffects"));
    r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    (d = new ActionDescriptor()).putReference(s2t("null"), r);
    d.putObject(s2t("to"), s2t("layerEffects"), fx);
    executeAction(s2t("set"), d, DialogModes.NO);
}

 

 

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
Explorer ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

thanks A LOT!

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 ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

LATEST
quote

thanks A LOT!


By @marior90336416

 

You're welcome, full credit to @jazz-y !

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

If I understand the question, another way is:

-click on "Color Overlay"

-Choose the blue foreground color

The other elements of the style (gradient, bevel & emboss, etc whatever they were) remain unchanged. As to the opacity issue, adjust the slider.  If this isn't what you meant, maybe post a screenshot?

1A.jpg

 

2A.jpg3A.jpg

 

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

@Leslie Moak Murray â€“ It's easy to miss the topic label/tag sometimes, this is a scripting question.

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

Well yes, but sometimes it seems to me there are easier ways (I am a Blonde Person.The very word "script" fills me with anxiety).

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 ,
Apr 15, 2023 Apr 15, 2023

Copy link to clipboard

Copied

That's funny, Leslie! 🤣 (I'm not a scripter either)

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